diff --git a/src/doc/book b/src/doc/book index 0e9061cbaf95a..fab9419503f0e 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit 0e9061cbaf95adfb9f3ed36c6cef4c046f282e86 +Subproject commit fab9419503f0e34c1a06f9350a6705d0ce741dc6 diff --git a/src/doc/unstable-book/src/language-features/c-variadic.md b/src/doc/unstable-book/src/language-features/c-variadic.md new file mode 100644 index 0000000000000..9e7968d906fbf --- /dev/null +++ b/src/doc/unstable-book/src/language-features/c-variadic.md @@ -0,0 +1,24 @@ +# `c_variadic` + +The tracking issue for this feature is: [#44930] + +[#44930]: https://github.com/rust-lang/rust/issues/44930 + +------------------------ + +The `c_variadic` language feature enables C-variadic functions to be +defined in Rust. The may be called both from within Rust and via FFI. + +## Examples + +```rust +#![feature(c_variadic)] + +pub unsafe extern "C" fn add(n: usize, mut args: ...) -> usize { + let mut sum = 0; + for _ in 0..n { + sum += args.arg::(); + } + sum +} +``` diff --git a/src/doc/unstable-book/src/library-features/c-variadic.md b/src/doc/unstable-book/src/library-features/c-variadic.md new file mode 100644 index 0000000000000..77762116e6b1c --- /dev/null +++ b/src/doc/unstable-book/src/library-features/c-variadic.md @@ -0,0 +1,26 @@ +# `c_variadic` + +The tracking issue for this feature is: [#44930] + +[#44930]: https://github.com/rust-lang/rust/issues/44930 + +------------------------ + +The `c_variadic` library feature exposes the `VaList` structure, +Rust's analogue of C's `va_list` type. + +## Examples + +```rust +#![feature(c_variadic)] + +use std::ffi::VaList; + +pub unsafe extern "C" fn vadd(n: usize, mut args: VaList) -> usize { + let mut sum = 0; + for _ in 0..n { + sum += args.arg::(); + } + sum +} +``` diff --git a/src/liballoc/string.rs b/src/liballoc/string.rs index 84c35c6f1bd2b..b714df5d36b6a 100644 --- a/src/liballoc/string.rs +++ b/src/liballoc/string.rs @@ -486,7 +486,7 @@ impl String { /// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html /// [`as_bytes`]: struct.String.html#method.as_bytes /// [`FromUtf8Error`]: struct.FromUtf8Error.html - /// [`Err`]: ../../stdresult/enum.Result.html#variant.Err + /// [`Err`]: ../../std/result/enum.Result.html#variant.Err #[inline] #[stable(feature = "rust1", since = "1.0.0")] pub fn from_utf8(vec: Vec) -> Result { @@ -2073,48 +2073,17 @@ impl ops::DerefMut for String { /// [`String`]: struct.String.html /// [`from_str`]: ../../std/str/trait.FromStr.html#tymethod.from_str #[stable(feature = "str_parse_error", since = "1.5.0")] -#[derive(Copy)] -pub enum ParseError {} +pub type ParseError = core::convert::Infallible; #[stable(feature = "rust1", since = "1.0.0")] impl FromStr for String { - type Err = ParseError; + type Err = core::convert::Infallible; #[inline] fn from_str(s: &str) -> Result { Ok(String::from(s)) } } -#[stable(feature = "str_parse_error", since = "1.5.0")] -impl Clone for ParseError { - fn clone(&self) -> ParseError { - match *self {} - } -} - -#[stable(feature = "str_parse_error", since = "1.5.0")] -impl fmt::Debug for ParseError { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self {} - } -} - -#[stable(feature = "str_parse_error2", since = "1.8.0")] -impl fmt::Display for ParseError { - fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self {} - } -} - -#[stable(feature = "str_parse_error", since = "1.5.0")] -impl PartialEq for ParseError { - fn eq(&self, _: &ParseError) -> bool { - match *self {} - } -} - -#[stable(feature = "str_parse_error", since = "1.5.0")] -impl Eq for ParseError {} /// A trait for converting a value to a `String`. /// diff --git a/src/libcore/array.rs b/src/libcore/array.rs index 3a27a39af4ace..9c6ecc4350246 100644 --- a/src/libcore/array.rs +++ b/src/libcore/array.rs @@ -49,7 +49,7 @@ unsafe impl> FixedSizeArray for A { } /// The error type returned when a conversion from a slice to an array fails. -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] #[derive(Debug, Copy, Clone)] pub struct TryFromSliceError(()); @@ -138,7 +138,7 @@ macro_rules! array_impls { } } - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl<'a, T> TryFrom<&'a [T]> for [T; $N] where T: Copy { type Error = TryFromSliceError; @@ -147,7 +147,7 @@ macro_rules! array_impls { } } - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl<'a, T> TryFrom<&'a [T]> for &'a [T; $N] { type Error = TryFromSliceError; @@ -161,7 +161,7 @@ macro_rules! array_impls { } } - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl<'a, T> TryFrom<&'a mut [T]> for &'a mut [T; $N] { type Error = TryFromSliceError; diff --git a/src/libcore/char/convert.rs b/src/libcore/char/convert.rs index 4a1a236b669f0..6a5abfb408f5b 100644 --- a/src/libcore/char/convert.rs +++ b/src/libcore/char/convert.rs @@ -218,7 +218,7 @@ impl FromStr for char { } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl TryFrom for char { type Error = CharTryFromError; @@ -233,11 +233,11 @@ impl TryFrom for char { } /// The error type returned when a conversion from u32 to char fails. -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] #[derive(Copy, Clone, Debug, PartialEq, Eq)] pub struct CharTryFromError(()); -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl fmt::Display for CharTryFromError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { "converted integer out of range for `char`".fmt(f) diff --git a/src/libcore/char/mod.rs b/src/libcore/char/mod.rs index 15e153bdfada2..f3369c4d94010 100644 --- a/src/libcore/char/mod.rs +++ b/src/libcore/char/mod.rs @@ -30,7 +30,7 @@ pub use self::convert::{from_u32, from_digit}; pub use self::convert::from_u32_unchecked; #[stable(feature = "char_from_str", since = "1.20.0")] pub use self::convert::ParseCharError; -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] pub use self::convert::CharTryFromError; #[stable(feature = "decode_utf16", since = "1.9.0")] pub use self::decode::{decode_utf16, DecodeUtf16, DecodeUtf16Error}; diff --git a/src/libcore/convert.rs b/src/libcore/convert.rs index b8d751cfbb6df..5ecfa9cde032e 100644 --- a/src/libcore/convert.rs +++ b/src/libcore/convert.rs @@ -41,6 +41,8 @@ #![stable(feature = "rust1", since = "1.0.0")] +use fmt; + /// An identity function. /// /// Two things are important to note about this function: @@ -367,22 +369,26 @@ pub trait From: Sized { /// /// [`TryFrom`]: trait.TryFrom.html /// [`Into`]: trait.Into.html -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] pub trait TryInto: Sized { /// The type returned in the event of a conversion error. + #[stable(feature = "try_from", since = "1.34.0")] type Error; /// Performs the conversion. + #[stable(feature = "try_from", since = "1.34.0")] fn try_into(self) -> Result; } /// Attempt to construct `Self` via a conversion. -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] pub trait TryFrom: Sized { /// The type returned in the event of a conversion error. + #[stable(feature = "try_from", since = "1.34.0")] type Error; /// Performs the conversion. + #[stable(feature = "try_from", since = "1.34.0")] fn try_from(value: T) -> Result; } @@ -450,7 +456,7 @@ impl From for T { // TryFrom implies TryInto -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl TryInto for T where U: TryFrom { type Error = U::Error; @@ -462,9 +468,9 @@ impl TryInto for T where U: TryFrom // Infallible conversions are semantically equivalent to fallible conversions // with an uninhabited error type. -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl TryFrom for T where U: Into { - type Error = !; + type Error = Infallible; fn try_from(value: U) -> Result { Ok(U::into(value)) @@ -496,3 +502,115 @@ impl AsRef for str { self } } + +//////////////////////////////////////////////////////////////////////////////// +// THE NO-ERROR ERROR TYPE +//////////////////////////////////////////////////////////////////////////////// + +/// The error type for errors that can never happen. +/// +/// Since this enum has no variant, a value of this type can never actually exist. +/// This can be useful for generic APIs that use [`Result`] and parameterize the error type, +/// to indicate that the result is always [`Ok`]. +/// +/// For example, the [`TryFrom`] trait (conversion that returns a [`Result`]) +/// has a blanket implementation for all types where a reverse [`Into`] implementation exists. +/// +/// ```ignore (illustrates std code, duplicating the impl in a doctest would be an error) +/// impl TryFrom for T where U: Into { +/// type Error = Infallible; +/// +/// fn try_from(value: U) -> Result { +/// Ok(U::into(value)) // Never returns `Err` +/// } +/// } +/// ``` +/// +/// # Future compatibility +/// +/// This enum has the same role as [the `!` “never” type][never], +/// which is unstable in this version of Rust. +/// When `!` is stabilized, we plan to make `Infallible` a type alias to it: +/// +/// ```ignore (illustrates future std change) +/// pub type Infallible = !; +/// ``` +/// +/// … and eventually deprecate `Infallible`. +/// +/// +/// However there is one case where `!` syntax can be used +/// before `!` is stabilized as a full-fleged type: in the position of a function’s return type. +/// Specifically, it is possible implementations for two different function pointer types: +/// +/// ``` +/// trait MyTrait {} +/// impl MyTrait for fn() -> ! {} +/// impl MyTrait for fn() -> std::convert::Infallible {} +/// ``` +/// +/// With `Infallible` being an enum, this code is valid. +/// However when `Infallible` becomes an alias for the never type, +/// the two `impl`s will start to overlap +/// and therefore will be disallowed by the language’s trait coherence rules. +/// +/// [`Ok`]: ../result/enum.Result.html#variant.Ok +/// [`Result`]: ../result/enum.Result.html +/// [`TryFrom`]: trait.TryFrom.html +/// [`Into`]: trait.Into.html +/// [never]: ../../std/primitive.never.html +#[stable(feature = "convert_infallible", since = "1.34.0")] +#[derive(Copy)] +pub enum Infallible {} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Clone for Infallible { + fn clone(&self) -> Infallible { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl fmt::Debug for Infallible { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl fmt::Display for Infallible { + fn fmt(&self, _: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl PartialEq for Infallible { + fn eq(&self, _: &Infallible) -> bool { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Eq for Infallible {} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl PartialOrd for Infallible { + fn partial_cmp(&self, _other: &Self) -> Option { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl Ord for Infallible { + fn cmp(&self, _other: &Self) -> crate::cmp::Ordering { + match *self {} + } +} + +#[stable(feature = "convert_infallible", since = "1.34.0")] +impl From for Infallible { + fn from(x: !) -> Self { + x + } +} diff --git a/src/libcore/lib.rs b/src/libcore/lib.rs index f2165c676fd44..63688e70c45cb 100644 --- a/src/libcore/lib.rs +++ b/src/libcore/lib.rs @@ -123,7 +123,6 @@ #![feature(abi_unadjusted)] #![feature(adx_target_feature)] #![feature(maybe_uninit, maybe_uninit_slice, maybe_uninit_array)] -#![feature(unrestricted_attribute_tokens)] #![feature(external_doc)] #[prelude_import] diff --git a/src/libcore/num/mod.rs b/src/libcore/num/mod.rs index 5b7d5f45d9246..3ceba83afeef8 100644 --- a/src/libcore/num/mod.rs +++ b/src/libcore/num/mod.rs @@ -2,7 +2,7 @@ #![stable(feature = "rust1", since = "1.0.0")] -use convert::TryFrom; +use convert::{TryFrom, Infallible}; use fmt; use intrinsics; use mem; @@ -2000,7 +2000,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -2032,7 +2031,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -2074,7 +2072,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -3767,7 +3764,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -3799,7 +3795,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -3841,7 +3836,6 @@ assert_eq!(value, ", $swap_op, "); When starting from a slice rather than an array, fallible conversion APIs can be used: ``` -#![feature(try_from)] use std::convert::TryInto; fn read_be_", stringify!($SelfT), "(input: &mut &[u8]) -> ", stringify!($SelfT), " { @@ -4504,7 +4498,7 @@ macro_rules! from_str_radix_int_impl { from_str_radix_int_impl! { isize i8 i16 i32 i64 i128 usize u8 u16 u32 u64 u128 } /// The error type returned when a checked integral type conversion fails. -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] #[derive(Debug, Copy, Clone, PartialEq, Eq)] pub struct TryFromIntError(()); @@ -4519,24 +4513,34 @@ impl TryFromIntError { } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl fmt::Display for TryFromIntError { fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { self.__description().fmt(fmt) } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] +impl From for TryFromIntError { + fn from(x: Infallible) -> TryFromIntError { + match x {} + } +} + +#[unstable(feature = "never_type", issue = "35121")] impl From for TryFromIntError { fn from(never: !) -> TryFromIntError { - never + // Match rather than coerce to make sure that code like + // `From for TryFromIntError` above will keep working + // when `Infallible` becomes an alias to `!`. + match never {} } } // no possible bounds violation macro_rules! try_from_unbounded { ($source:ty, $($target:ty),*) => {$( - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl TryFrom<$source> for $target { type Error = TryFromIntError; @@ -4551,7 +4555,7 @@ macro_rules! try_from_unbounded { // only negative bounds macro_rules! try_from_lower_bounded { ($source:ty, $($target:ty),*) => {$( - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl TryFrom<$source> for $target { type Error = TryFromIntError; @@ -4570,7 +4574,7 @@ macro_rules! try_from_lower_bounded { // unsigned to signed (only positive bound) macro_rules! try_from_upper_bounded { ($source:ty, $($target:ty),*) => {$( - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl TryFrom<$source> for $target { type Error = TryFromIntError; @@ -4589,7 +4593,7 @@ macro_rules! try_from_upper_bounded { // all other cases macro_rules! try_from_both_bounded { ($source:ty, $($target:ty),*) => {$( - #[unstable(feature = "try_from", issue = "33417")] + #[stable(feature = "try_from", since = "1.34.0")] impl TryFrom<$source> for $target { type Error = TryFromIntError; diff --git a/src/libcore/tests/lib.rs b/src/libcore/tests/lib.rs index 4cd734bad90a4..d002137638977 100644 --- a/src/libcore/tests/lib.rs +++ b/src/libcore/tests/lib.rs @@ -26,7 +26,6 @@ #![feature(str_internals)] #![feature(test)] #![feature(trusted_len)] -#![feature(try_from)] #![feature(try_trait)] #![feature(align_offset)] #![feature(reverse_bits)] diff --git a/src/librustc/cfg/construct.rs b/src/librustc/cfg/construct.rs index 9eeae6eeb5f34..30a0477467d80 100644 --- a/src/librustc/cfg/construct.rs +++ b/src/librustc/cfg/construct.rs @@ -398,7 +398,7 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> { args: I) -> CFGIndex { let func_or_rcvr_exit = self.expr(func_or_rcvr, pred); let ret = self.straightline(call_expr, func_or_rcvr_exit, args); - let m = self.tcx.hir().get_module_parent(call_expr.id); + let m = self.tcx.hir().get_module_parent_by_hir_id(call_expr.hir_id); if self.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(call_expr)) { self.add_unreachable_node() } else { diff --git a/src/librustc/dep_graph/dep_node.rs b/src/librustc/dep_graph/dep_node.rs index 2f91da4f62e3d..0d8f71a50ce52 100644 --- a/src/librustc/dep_graph/dep_node.rs +++ b/src/librustc/dep_graph/dep_node.rs @@ -67,7 +67,7 @@ use crate::traits::query::{ }; use crate::ty::{TyCtxt, FnSig, Instance, InstanceDef, ParamEnv, ParamEnvAnd, Predicate, PolyFnSig, PolyTraitRef, Ty}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; // erase!() just makes tokens go away. It's used to specify which macro argument // is repeated (i.e., which sub-expression of the macro we are in) but don't need @@ -661,7 +661,7 @@ define_dep_nodes!( <'tcx> [] TypeOpNormalizePolyFnSig(CanonicalTypeOpNormalizeGoal<'tcx, PolyFnSig<'tcx>>), [] TypeOpNormalizeFnSig(CanonicalTypeOpNormalizeGoal<'tcx, FnSig<'tcx>>), - [] SubstituteNormalizeAndTestPredicates { key: (DefId, &'tcx Substs<'tcx>) }, + [] SubstituteNormalizeAndTestPredicates { key: (DefId, SubstsRef<'tcx>) }, [] MethodAutoderefSteps(CanonicalTyGoal<'tcx>), [input] TargetFeaturesWhitelist, diff --git a/src/librustc/hir/intravisit.rs b/src/librustc/hir/intravisit.rs index 0bc40da7e4f2c..8e4b9a5e8e641 100644 --- a/src/librustc/hir/intravisit.rs +++ b/src/librustc/hir/intravisit.rs @@ -617,6 +617,9 @@ 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 d55f62d3e1a59..7a6c7f1e89979 100644 --- a/src/librustc/hir/lowering.rs +++ b/src/librustc/hir/lowering.rs @@ -74,7 +74,7 @@ const HIR_ID_COUNTER_LOCKED: u32 = 0xFFFFFFFF; pub struct LoweringContext<'a> { crate_root: Option<&'static str>, - // Used to assign ids to HIR nodes that do not directly correspond to an AST node. + /// Used to assign ids to HIR nodes that do not directly correspond to an AST node. sess: &'a Session, cstore: &'a dyn CrateStore, @@ -107,25 +107,25 @@ pub struct LoweringContext<'a> { /// written at all (e.g., `&T` or `std::cell::Ref`). anonymous_lifetime_mode: AnonymousLifetimeMode, - // Used to create lifetime definitions from in-band lifetime usages. - // e.g., `fn foo(x: &'x u8) -> &'x u8` to `fn foo<'x>(x: &'x u8) -> &'x u8` - // When a named lifetime is encountered in a function or impl header and - // has not been defined - // (i.e., it doesn't appear in the in_scope_lifetimes list), it is added - // to this list. The results of this list are then added to the list of - // lifetime definitions in the corresponding impl or function generics. + /// Used to create lifetime definitions from in-band lifetime usages. + /// e.g., `fn foo(x: &'x u8) -> &'x u8` to `fn foo<'x>(x: &'x u8) -> &'x u8` + /// When a named lifetime is encountered in a function or impl header and + /// has not been defined + /// (i.e., it doesn't appear in the in_scope_lifetimes list), it is added + /// to this list. The results of this list are then added to the list of + /// lifetime definitions in the corresponding impl or function generics. lifetimes_to_define: Vec<(Span, ParamName)>, - // Whether or not in-band lifetimes are being collected. This is used to - // indicate whether or not we're in a place where new lifetimes will result - // in in-band lifetime definitions, such a function or an impl header, - // including implicit lifetimes from `impl_header_lifetime_elision`. + /// Whether or not in-band lifetimes are being collected. This is used to + /// indicate whether or not we're in a place where new lifetimes will result + /// in in-band lifetime definitions, such a function or an impl header, + /// including implicit lifetimes from `impl_header_lifetime_elision`. is_collecting_in_band_lifetimes: bool, - // Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB. - // When `is_collectin_in_band_lifetimes` is true, each lifetime is checked - // against this list to see if it is already in-scope, or if a definition - // needs to be created for it. + /// Currently in-scope lifetimes defined in impl headers, fn headers, or HRTB. + /// When `is_collectin_in_band_lifetimes` is true, each lifetime is checked + /// against this list to see if it is already in-scope, or if a definition + /// needs to be created for it. in_scope_lifetimes: Vec, current_module: NodeId, @@ -780,7 +780,6 @@ impl<'a> LoweringContext<'a> { ); hir::GenericParam { - id: node_id, hir_id, name: hir_name, attrs: hir_vec![], @@ -955,7 +954,7 @@ impl<'a> LoweringContext<'a> { let decl = FnDecl { inputs: vec![], output, - variadic: false + c_variadic: false }; let body_id = self.record_body(body_expr, Some(&decl)); self.is_generator = prev_is_generator; @@ -964,7 +963,6 @@ impl<'a> LoweringContext<'a> { let closure_hir_id = self.lower_node_id(closure_node_id).hir_id; let decl = self.lower_fn_decl(&decl, None, /* impl trait allowed */ false, None); let generator = hir::Expr { - id: closure_node_id, hir_id: closure_hir_id, node: hir::ExprKind::Closure(capture_clause, decl, body_id, span, Some(hir::GeneratorMovability::Static)), @@ -1300,7 +1298,6 @@ impl<'a> LoweringContext<'a> { // Set the name to `impl Bound1 + Bound2`. let ident = Ident::from_str(&pprust::ty_to_string(t)).with_span_pos(span); in_band_ty_params.push(hir::GenericParam { - id: def_node_id, hir_id, name: ParamName::Plain(ident), pure_wrt_drop: false, @@ -1348,11 +1345,16 @@ impl<'a> LoweringContext<'a> { } } TyKind::Mac(_) => panic!("TyMac should have been expanded by now."), + TyKind::CVarArgs => { + // Create the implicit lifetime of the "spoofed" `VaList`. + let span = self.sess.source_map().next_point(t.span.shrink_to_lo()); + let lt = self.new_implicit_lifetime(span); + hir::TyKind::CVarArgs(lt) + }, }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(t.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(t.id); hir::Ty { - id: node_id, node: kind, span: t.span, hir_id, @@ -1394,12 +1396,11 @@ impl<'a> LoweringContext<'a> { ); self.with_hir_id_owner(exist_ty_node_id, |lctx| { - let LoweredNodeId { node_id, hir_id } = lctx.next_id(); + let LoweredNodeId { node_id: _, hir_id } = lctx.next_id(); let exist_ty_item_kind = hir::ItemKind::Existential(hir::ExistTy { generics: hir::Generics { params: lifetime_defs, where_clause: hir::WhereClause { - id: node_id, hir_id, predicates: Vec::new().into(), }, @@ -1533,9 +1534,8 @@ impl<'a> LoweringContext<'a> { && !self.already_defined_lifetimes.contains(&name) { self.already_defined_lifetimes.insert(name); - let LoweredNodeId { node_id, hir_id } = self.context.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.context.next_id(); self.output_lifetimes.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: node_id, hir_id, span: lifetime.span, name, @@ -1569,7 +1569,6 @@ impl<'a> LoweringContext<'a> { }; self.output_lifetime_params.push(hir::GenericParam { - id: def_node_id, hir_id, name, span: lifetime.span, @@ -1980,8 +1979,8 @@ impl<'a> LoweringContext<'a> { .map(|ty| this.lower_ty_direct(ty, ImplTraitContext::disallowed())) .collect(); let mk_tup = |this: &mut Self, tys, span| { - let LoweredNodeId { node_id, hir_id } = this.next_id(); - hir::Ty { node: hir::TyKind::Tup(tys), id: node_id, hir_id, span } + let LoweredNodeId { node_id: _, hir_id } = this.next_id(); + hir::Ty { node: hir::TyKind::Tup(tys), hir_id, span } }; let LoweredNodeId { node_id, hir_id } = this.next_id(); @@ -2119,7 +2118,7 @@ impl<'a> LoweringContext<'a> { P(hir::FnDecl { inputs, output, - variadic: decl.variadic, + c_variadic: decl.c_variadic, implicit_self: decl.inputs.get(0).map_or( hir::ImplicitSelfKind::None, |arg| { @@ -2318,9 +2317,8 @@ impl<'a> LoweringContext<'a> { this.lower_ty(ty, ImplTraitContext::Existential(Some(fn_def_id))) } FunctionRetTy::Default(span) => { - let LoweredNodeId { node_id, hir_id } = this.next_id(); + let LoweredNodeId { node_id: _, hir_id } = this.next_id(); P(hir::Ty { - id: node_id, hir_id, node: hir::TyKind::Tup(hir_vec![]), span: *span, @@ -2362,17 +2360,16 @@ impl<'a> LoweringContext<'a> { ]; if let Some((name, span)) = bound_lifetime { - let LoweredNodeId { node_id, hir_id } = this.next_id(); + let LoweredNodeId { node_id: _, hir_id } = this.next_id(); bounds.push(hir::GenericBound::Outlives( - hir::Lifetime { id: node_id, hir_id, name, span })); + hir::Lifetime { hir_id, name, span })); } hir::HirVec::from(bounds) }); - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let impl_trait_ty = P(hir::Ty { - id: node_id, node: impl_trait_ty, span, hir_id, @@ -2431,10 +2428,9 @@ impl<'a> LoweringContext<'a> { span: Span, name: hir::LifetimeName, ) -> hir::Lifetime { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); hir::Lifetime { - id: node_id, hir_id, span, name: name, @@ -2524,10 +2520,9 @@ impl<'a> LoweringContext<'a> { } }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(param.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(param.id); hir::GenericParam { - id: node_id, hir_id, name, span: param.ident.span, @@ -2608,10 +2603,9 @@ impl<'a> LoweringContext<'a> { self.with_anonymous_lifetime_mode( AnonymousLifetimeMode::ReportError, |this| { - let LoweredNodeId { node_id, hir_id } = this.lower_node_id(wc.id); + let LoweredNodeId { node_id: _, hir_id } = this.lower_node_id(wc.id); hir::WhereClause { - id: node_id, hir_id, predicates: wc.predicates .iter() @@ -2672,10 +2666,9 @@ impl<'a> LoweringContext<'a> { ref rhs_ty, span, }) => { - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(id); hir::WherePredicate::EqPredicate(hir::WhereEqPredicate { - id: node_id, hir_id, lhs_ty: self.lower_ty(lhs_ty, ImplTraitContext::disallowed()), rhs_ty: self.lower_ty(rhs_ty, ImplTraitContext::disallowed()), @@ -2816,10 +2809,9 @@ impl<'a> LoweringContext<'a> { } } - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(b.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(b.id); P(hir::Block { - id: node_id, hir_id, stmts: stmts.into(), expr, @@ -3544,7 +3536,6 @@ impl<'a> LoweringContext<'a> { name: ident.name, vis, attrs, - id: i.id, hir_id, span: i.span, body, @@ -3900,11 +3891,10 @@ impl<'a> LoweringContext<'a> { // Wrap the `if let` expr in a block. let span = els.span; let els = P(self.lower_expr(els)); - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); let blk = P(hir::Block { stmts: hir_vec![], expr: Some(els), - id: node_id, hir_id, rules: hir::DefaultBlock, span, @@ -3947,10 +3937,9 @@ impl<'a> LoweringContext<'a> { let mut block = this.lower_block(body, true).into_inner(); let tail = block.expr.take().map_or_else( || { - let LoweredNodeId { node_id, hir_id } = this.next_id(); + let LoweredNodeId { node_id: _, hir_id } = this.next_id(); let span = this.sess.source_map().end_point(unstable_span); hir::Expr { - id: node_id, span, node: hir::ExprKind::Tup(hir_vec![]), attrs: ThinVec::new(), @@ -3984,7 +3973,7 @@ impl<'a> LoweringContext<'a> { let outer_decl = FnDecl { inputs: decl.inputs.clone(), output: FunctionRetTy::Default(fn_decl_span), - variadic: false, + 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 @@ -4135,10 +4124,9 @@ impl<'a> LoweringContext<'a> { let struct_path = self.std_path(e.span, &struct_path, None, is_unit); let struct_path = hir::QPath::Resolved(None, P(struct_path)); - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); return hir::Expr { - id: node_id, hir_id, node: if is_unit { hir::ExprKind::Path(struct_path) @@ -4488,9 +4476,8 @@ impl<'a> LoweringContext<'a> { self.lower_label(opt_label), hir::LoopSource::ForLoop, ); - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); let loop_expr = P(hir::Expr { - id: node_id, hir_id, node: loop_expr, span: e.span, @@ -4635,10 +4622,9 @@ impl<'a> LoweringContext<'a> { ExprKind::Mac(_) => panic!("Shouldn't exist here"), }; - let LoweredNodeId { node_id, hir_id } = self.lower_node_id(e.id); + let LoweredNodeId { node_id: _, hir_id } = self.lower_node_id(e.id); hir::Expr { - id: node_id, hir_id, node: kind, span: e.span, @@ -4910,9 +4896,8 @@ impl<'a> LoweringContext<'a> { } fn expr(&mut self, span: Span, node: hir::ExprKind, attrs: ThinVec) -> hir::Expr { - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Expr { - id: node_id, hir_id, node, span, @@ -4978,12 +4963,11 @@ impl<'a> LoweringContext<'a> { stmts: hir::HirVec, expr: Option>, ) -> hir::Block { - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Block { stmts, expr, - id: node_id, hir_id, rules: hir::DefaultBlock, span, @@ -5108,7 +5092,6 @@ impl<'a> LoweringContext<'a> { _ => hir::TyKind::Path(qpath), }; hir::Ty { - id: id.node_id, hir_id: id.hir_id, node, span, @@ -5124,9 +5107,8 @@ impl<'a> LoweringContext<'a> { // `'f`. AnonymousLifetimeMode::CreateParameter => { let fresh_name = self.collect_fresh_in_band_lifetime(span); - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Lifetime { - id: node_id, hir_id, span, name: hir::LifetimeName::Param(fresh_name), @@ -5227,10 +5209,9 @@ impl<'a> LoweringContext<'a> { } fn new_implicit_lifetime(&mut self, span: Span) -> hir::Lifetime { - let LoweredNodeId { node_id, hir_id } = self.next_id(); + let LoweredNodeId { node_id: _, hir_id } = self.next_id(); hir::Lifetime { - id: node_id, hir_id, span, name: hir::LifetimeName::Implicit, diff --git a/src/librustc/hir/map/blocks.rs b/src/librustc/hir/map/blocks.rs index 6919628c76755..1114ef52bbc0c 100644 --- a/src/librustc/hir/map/blocks.rs +++ b/src/librustc/hir/map/blocks.rs @@ -75,10 +75,10 @@ pub enum Code<'a> { } impl<'a> Code<'a> { - pub fn id(&self) -> NodeId { + pub fn id(&self) -> ast::HirId { match *self { Code::FnLike(node) => node.id(), - Code::Expr(block) => block.id, + Code::Expr(block) => block.hir_id, } } @@ -104,7 +104,7 @@ struct ItemFnParts<'a> { vis: &'a ast::Visibility, generics: &'a ast::Generics, body: ast::BodyId, - id: NodeId, + id: ast::HirId, span: Span, attrs: &'a [Attribute], } @@ -114,13 +114,13 @@ struct ItemFnParts<'a> { struct ClosureParts<'a> { decl: &'a FnDecl, body: ast::BodyId, - id: NodeId, + id: ast::HirId, span: Span, attrs: &'a [Attribute], } impl<'a> ClosureParts<'a> { - fn new(d: &'a FnDecl, b: ast::BodyId, id: NodeId, s: Span, attrs: &'a [Attribute]) -> Self { + fn new(d: &'a FnDecl, b: ast::BodyId, id: ast::HirId, s: Span, attrs: &'a [Attribute]) -> Self { ClosureParts { decl: d, body: b, @@ -168,7 +168,7 @@ impl<'a> FnLikeNode<'a> { |c: ClosureParts<'_>| c.span) } - pub fn id(self) -> NodeId { + pub fn id(self) -> ast::HirId { self.handle(|i: ItemFnParts<'_>| i.id, |id, _, _: &'a ast::MethodSig, _, _, _, _| id, |c: ClosureParts<'_>| c.id) @@ -213,7 +213,7 @@ impl<'a> FnLikeNode<'a> { fn handle(self, item_fn: I, method: M, closure: C) -> A where I: FnOnce(ItemFnParts<'a>) -> A, - M: FnOnce(NodeId, + M: FnOnce(ast::HirId, Ident, &'a ast::MethodSig, Option<&'a ast::Visibility>, @@ -227,7 +227,7 @@ impl<'a> FnLikeNode<'a> { map::Node::Item(i) => match i.node { ast::ItemKind::Fn(ref decl, header, ref generics, block) => item_fn(ItemFnParts { - id: i.id, + id: i.hir_id, ident: i.ident, decl: &decl, body: block, @@ -241,21 +241,21 @@ impl<'a> FnLikeNode<'a> { }, map::Node::TraitItem(ti) => match ti.node { ast::TraitItemKind::Method(ref sig, ast::TraitMethod::Provided(body)) => { - method(ti.id, ti.ident, sig, None, body, ti.span, &ti.attrs) + method(ti.hir_id, ti.ident, sig, None, body, ti.span, &ti.attrs) } _ => bug!("trait method FnLikeNode that is not fn-like"), }, map::Node::ImplItem(ii) => { match ii.node { ast::ImplItemKind::Method(ref sig, body) => { - method(ii.id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs) + method(ii.hir_id, ii.ident, sig, Some(&ii.vis), body, ii.span, &ii.attrs) } _ => bug!("impl method FnLikeNode that is not fn-like") } }, map::Node::Expr(e) => match e.node { ast::ExprKind::Closure(_, ref decl, block, _fn_decl_span, _gen) => - closure(ClosureParts::new(&decl, block, e.id, e.span, &e.attrs)), + closure(ClosureParts::new(&decl, block, e.hir_id, e.span, &e.attrs)), _ => bug!("expr FnLikeNode that is not fn-like"), }, _ => bug!("other FnLikeNode that is not fn-like"), diff --git a/src/librustc/hir/map/collector.rs b/src/librustc/hir/map/collector.rs index 04eec88004aa6..588b986aad29d 100644 --- a/src/librustc/hir/map/collector.rs +++ b/src/librustc/hir/map/collector.rs @@ -507,7 +507,8 @@ impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> { } fn visit_macro_def(&mut self, macro_def: &'hir MacroDef) { - let def_index = self.definitions.opt_def_index(macro_def.id).unwrap(); + let node_id = self.hir_to_node_id[¯o_def.hir_id]; + let def_index = self.definitions.opt_def_index(node_id).unwrap(); self.with_dep_node_owner(def_index, macro_def, |this| { this.insert(macro_def.span, macro_def.hir_id, Node::MacroDef(macro_def)); diff --git a/src/librustc/hir/map/mod.rs b/src/librustc/hir/map/mod.rs index 39203208855e0..41e48e46ea5b6 100644 --- a/src/librustc/hir/map/mod.rs +++ b/src/librustc/hir/map/mod.rs @@ -390,14 +390,19 @@ impl<'hir> Map<'hir> { Some(Def::Local(local.id)) } Node::MacroDef(macro_def) => { - Some(Def::Macro(self.local_def_id(macro_def.id), + Some(Def::Macro(self.local_def_id_from_hir_id(macro_def.hir_id), MacroKind::Bang)) } Node::GenericParam(param) => { Some(match param.kind { - GenericParamKind::Lifetime { .. } => Def::Local(param.id), - GenericParamKind::Type { .. } => Def::TyParam(self.local_def_id(param.id)), - GenericParamKind::Const { .. } => Def::ConstParam(self.local_def_id(param.id)), + GenericParamKind::Lifetime { .. } => { + let node_id = self.hir_to_node_id(param.hir_id); + Def::Local(node_id) + }, + GenericParamKind::Type { .. } => Def::TyParam( + self.local_def_id_from_hir_id(param.hir_id)), + GenericParamKind::Const { .. } => Def::ConstParam( + self.local_def_id_from_hir_id(param.hir_id)), }) } } @@ -794,7 +799,7 @@ impl<'hir> Map<'hir> { /// false /// } /// ``` - pub fn get_return_block(&self, id: NodeId) -> Option { + pub fn get_return_block(&self, id: HirId) -> Option { let match_fn = |node: &Node<'_>| { match *node { Node::Item(_) | @@ -817,7 +822,10 @@ impl<'hir> Map<'hir> { } }; - self.walk_parent_nodes(id, match_fn, match_non_returning_block).ok() + let node_id = self.hir_to_node_id(id); + self.walk_parent_nodes(node_id, match_fn, match_non_returning_block) + .ok() + .map(|return_node_id| self.node_to_hir_id(return_node_id)) } /// Retrieves the `NodeId` for `id`'s parent item, or `id` itself if no diff --git a/src/librustc/hir/mod.rs b/src/librustc/hir/mod.rs index df02b91996f34..d8169d05dd4d0 100644 --- a/src/librustc/hir/mod.rs +++ b/src/librustc/hir/mod.rs @@ -19,7 +19,7 @@ use errors::FatalError; use syntax_pos::{Span, DUMMY_SP, symbol::InternedString}; use syntax::source_map::Spanned; use rustc_target::spec::abi::Abi; -use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, DUMMY_NODE_ID, AsmDialect}; +use syntax::ast::{self, CrateSugar, Ident, Name, NodeId, AsmDialect}; use syntax::ast::{Attribute, Label, Lit, StrStyle, FloatTy, IntTy, UintTy}; use syntax::attr::{InlineAttr, OptimizeAttr}; use syntax::ext::hygiene::SyntaxContext; @@ -112,6 +112,12 @@ impl serialize::UseSpecializedDecodable for HirId { } } +impl fmt::Display for HirId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{:?}", self) + } +} + // hack to ensure that we don't try to access the private parts of `ItemLocalId` in this module mod item_local_id_inner { use rustc_data_structures::indexed_vec::Idx; @@ -145,7 +151,6 @@ pub const DUMMY_ITEM_LOCAL_ID: ItemLocalId = ItemLocalId::MAX; #[derive(Clone, RustcEncodable, RustcDecodable, Copy)] pub struct Lifetime { - pub id: NodeId, pub hir_id: HirId, pub span: Span, @@ -266,7 +271,7 @@ impl fmt::Debug for Lifetime { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "lifetime({}: {})", - self.id, + self.hir_id, print::to_string(print::NO_ANN, |s| s.print_lifetime(self))) } } @@ -411,11 +416,11 @@ impl GenericArg { } } - pub fn id(&self) -> NodeId { + pub fn id(&self) -> HirId { match self { - GenericArg::Lifetime(l) => l.id, - GenericArg::Type(t) => t.id, - GenericArg::Const(c) => c.value.id, + GenericArg::Lifetime(l) => l.hir_id, + GenericArg::Type(t) => t.hir_id, + GenericArg::Const(c) => c.value.hir_id, } } } @@ -547,7 +552,6 @@ pub enum GenericParamKind { #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct GenericParam { - pub id: NodeId, pub hir_id: HirId, pub name: ParamName, pub attrs: HirVec, @@ -579,7 +583,6 @@ impl Generics { Generics { params: HirVec::new(), where_clause: WhereClause { - id: DUMMY_NODE_ID, hir_id: DUMMY_HIR_ID, predicates: HirVec::new(), }, @@ -624,7 +627,6 @@ pub enum SyntheticTyParamKind { /// A where-clause in a definition. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereClause { - pub id: NodeId, pub hir_id: HirId, pub predicates: HirVec, } @@ -685,7 +687,6 @@ pub struct WhereRegionPredicate { /// An equality predicate (e.g., `T = int`); currently unsupported. #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] pub struct WhereEqPredicate { - pub id: NodeId, pub hir_id: HirId, pub span: Span, pub lhs_ty: P, @@ -808,7 +809,6 @@ pub struct MacroDef { pub name: Name, pub vis: Visibility, pub attrs: HirVec, - pub id: NodeId, pub hir_id: HirId, pub span: Span, pub body: TokenStream, @@ -822,7 +822,6 @@ pub struct Block { /// An expression at the end of the block /// without a semicolon, if any. pub expr: Option>, - pub id: NodeId, pub hir_id: HirId, /// Distinguishes between `unsafe { ... }` and `{ ... }`. pub rules: BlockCheckMode, @@ -1334,7 +1333,6 @@ pub struct AnonConst { /// An expression #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Expr { - pub id: NodeId, pub span: Span, pub node: ExprKind, pub attrs: ThinVec, @@ -1437,7 +1435,7 @@ impl Expr { impl fmt::Debug for Expr { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "expr({}: {})", self.id, + write!(f, "expr({}: {})", self.hir_id, print::to_string(print::NO_ANN, |s| s.print_expr(self))) } } @@ -1754,7 +1752,6 @@ pub struct TypeBinding { #[derive(Clone, RustcEncodable, RustcDecodable)] pub struct Ty { - pub id: NodeId, pub node: TyKind, pub span: Span, pub hir_id: HirId, @@ -1832,6 +1829,9 @@ pub enum TyKind { Infer, /// Placeholder for a type that has failed to be defined. Err, + /// Placeholder for C-variadic arguments. We "spoof" the `VaList` created + /// from the variadic arguments. This type is only valid up to typeck. + CVarArgs(Lifetime), } #[derive(Clone, RustcEncodable, RustcDecodable, Debug)] @@ -1868,7 +1868,7 @@ pub struct Arg { pub struct FnDecl { pub inputs: HirVec, pub output: FunctionRetTy, - pub variadic: bool, + pub c_variadic: bool, /// Does the function have an implicit self? pub implicit_self: ImplicitSelfKind, } diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index ece649cf1b882..dab4b9c824d9a 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -434,6 +434,9 @@ impl<'a> State<'a> { self.s.word("/*ERROR*/")?; self.pclose()?; } + hir::TyKind::CVarArgs(_) => { + self.s.word("...")?; + } } self.end() } @@ -2004,7 +2007,7 @@ impl<'a> State<'a> { s.print_type(ty)?; s.end() })?; - if decl.variadic { + if decl.c_variadic { self.s.word(", ...")?; } self.pclose()?; @@ -2248,7 +2251,6 @@ impl<'a> State<'a> { let generics = hir::Generics { params: hir::HirVec::new(), where_clause: hir::WhereClause { - id: ast::DUMMY_NODE_ID, hir_id: hir::DUMMY_HIR_ID, predicates: hir::HirVec::new(), }, diff --git a/src/librustc/ich/impls_hir.rs b/src/librustc/ich/impls_hir.rs index 727c441b0e8db..775822786900a 100644 --- a/src/librustc/ich/impls_hir.rs +++ b/src/librustc/ich/impls_hir.rs @@ -158,7 +158,6 @@ impl_stable_hash_for!(struct ast::Label { }); impl_stable_hash_for!(struct hir::Lifetime { - id, hir_id, span, name @@ -207,7 +206,6 @@ impl_stable_hash_for!(enum hir::TraitBoundModifier { }); impl_stable_hash_for!(struct hir::GenericParam { - id, hir_id, name, pure_wrt_drop, @@ -255,7 +253,6 @@ impl_stable_hash_for!(enum hir::SyntheticTyParamKind { }); impl_stable_hash_for!(struct hir::WhereClause { - id, hir_id, predicates }); @@ -280,7 +277,6 @@ impl_stable_hash_for!(struct hir::WhereRegionPredicate { }); impl_stable_hash_for!(struct hir::WhereEqPredicate { - id, hir_id, span, lhs_ty, @@ -318,7 +314,6 @@ impl<'a> HashStable> for hir::Ty { hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Ty { - id: _, hir_id: _, ref node, ref span, @@ -366,13 +361,14 @@ impl_stable_hash_for!(enum hir::TyKind { TraitObject(trait_refs, lifetime), Typeof(body_id), Err, - Infer + Infer, + CVarArgs(lt), }); impl_stable_hash_for!(struct hir::FnDecl { inputs, output, - variadic, + c_variadic, implicit_self }); @@ -411,7 +407,6 @@ impl_stable_hash_for!(struct hir::MacroDef { name, vis, attrs, - id, hir_id, span, legacy, @@ -421,7 +416,6 @@ impl_stable_hash_for!(struct hir::MacroDef { impl_stable_hash_for!(struct hir::Block { stmts, expr, - id -> _, hir_id -> _, rules, span, @@ -566,7 +560,6 @@ impl<'a> HashStable> for hir::Expr { hasher: &mut StableHasher) { hcx.while_hashing_hir_bodies(true, |hcx| { let hir::Expr { - id: _, hir_id: _, ref span, ref node, diff --git a/src/librustc/ich/impls_ty.rs b/src/librustc/ich/impls_ty.rs index cce1273b7f025..f77a88128f252 100644 --- a/src/librustc/ich/impls_ty.rs +++ b/src/librustc/ich/impls_ty.rs @@ -232,7 +232,7 @@ impl_stable_hash_for!(struct ty::GenSig<'tcx> { impl_stable_hash_for!(struct ty::FnSig<'tcx> { inputs_and_output, - variadic, + c_variadic, unsafety, abi }); diff --git a/src/librustc/infer/combine.rs b/src/librustc/infer/combine.rs index 9cd5a844f1590..6ef902a47dc8d 100644 --- a/src/librustc/infer/combine.rs +++ b/src/librustc/infer/combine.rs @@ -34,7 +34,7 @@ use crate::ty::{IntType, UintType}; use crate::ty::{self, Ty, TyCtxt}; use crate::ty::error::TypeError; use crate::ty::relate::{self, Relate, RelateResult, TypeRelation}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::traits::{Obligation, PredicateObligations}; use syntax::ast; @@ -373,9 +373,9 @@ impl<'cx, 'gcx, 'tcx> TypeRelation<'cx, 'gcx, 'tcx> for Generalizer<'cx, 'gcx, ' fn relate_item_substs(&mut self, item_def_id: DefId, - a_subst: &'tcx Substs<'tcx>, - b_subst: &'tcx Substs<'tcx>) - -> RelateResult<'tcx, &'tcx Substs<'tcx>> + a_subst: SubstsRef<'tcx>, + b_subst: SubstsRef<'tcx>) + -> RelateResult<'tcx, SubstsRef<'tcx>> { if self.ambient_variance == ty::Variance::Invariant { // Avoid fetching the variance if we are in an invariant diff --git a/src/librustc/infer/equate.rs b/src/librustc/infer/equate.rs index a4b62307a60b8..31b01eecf5cb6 100644 --- a/src/librustc/infer/equate.rs +++ b/src/librustc/infer/equate.rs @@ -5,7 +5,7 @@ use crate::hir::def_id::DefId; use crate::ty::{self, Ty, TyCtxt}; use crate::ty::TyVar; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::ty::relate::{self, Relate, RelateResult, TypeRelation}; /// Ensures `a` is made equal to `b`. Returns `a` on success. @@ -33,9 +33,9 @@ impl<'combine, 'infcx, 'gcx, 'tcx> TypeRelation<'infcx, 'gcx, 'tcx> fn relate_item_substs(&mut self, _item_def_id: DefId, - a_subst: &'tcx Substs<'tcx>, - b_subst: &'tcx Substs<'tcx>) - -> RelateResult<'tcx, &'tcx Substs<'tcx>> + a_subst: SubstsRef<'tcx>, + b_subst: SubstsRef<'tcx>) + -> RelateResult<'tcx, SubstsRef<'tcx>> { // N.B., once we are equating types, we don't care about // variance, so don't try to lookup the variance here. This diff --git a/src/librustc/infer/error_reporting/mod.rs b/src/librustc/infer/error_reporting/mod.rs index 705d9c4cf93ea..3dace2f2e89b0 100644 --- a/src/librustc/infer/error_reporting/mod.rs +++ b/src/librustc/infer/error_reporting/mod.rs @@ -56,7 +56,7 @@ use crate::hir::Node; use crate::middle::region; use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::ty::error::TypeError; -use crate::ty::{self, subst::Subst, Region, Ty, TyCtxt, TyKind, TypeFoldable}; +use crate::ty::{self, subst::{Subst, SubstsRef}, Region, Ty, TyCtxt, TyKind, TypeFoldable}; use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString}; use std::{cmp, fmt}; use syntax_pos::{Pos, Span}; @@ -570,7 +570,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { value: &mut DiagnosticStyledString, other_value: &mut DiagnosticStyledString, name: String, - sub: &ty::subst::Substs<'tcx>, + sub: ty::subst::SubstsRef<'tcx>, pos: usize, other_ty: &Ty<'tcx>, ) { @@ -648,7 +648,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { mut t1_out: &mut DiagnosticStyledString, mut t2_out: &mut DiagnosticStyledString, path: String, - sub: &ty::subst::Substs<'tcx>, + sub: ty::subst::SubstsRef<'tcx>, other_path: String, other_ty: &Ty<'tcx>, ) -> Option<()> { @@ -687,8 +687,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { fn strip_generic_default_params( &self, def_id: DefId, - substs: &ty::subst::Substs<'tcx>, - ) -> &'tcx ty::subst::Substs<'tcx> { + substs: ty::subst::SubstsRef<'tcx>, + ) -> SubstsRef<'tcx> { let generics = self.tcx.generics_of(def_id); let mut num_supplied_defaults = 0; let mut type_params = generics 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 5d5a9b36087a2..86d7a19bc8309 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 @@ -101,7 +101,7 @@ impl<'a, 'gcx, 'tcx> NiceRegionError<'a, 'gcx, 'tcx> { let (span_1, span_2, main_label, span_label) = match (sup_is_ret_type, sub_is_ret_type) { (None, None) => { - let (main_label_1, span_label_1) = if ty_sup.id == ty_sub.id { + let (main_label_1, span_label_1) = if ty_sup.hir_id == ty_sub.hir_id { ( "this type is declared with multiple lifetimes...".to_owned(), "...but data with one lifetime flows into the other here".to_owned() diff --git a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs index 3b2fb7d41008e..506388c268bb1 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs @@ -7,7 +7,7 @@ use crate::infer::{SubregionOrigin, TypeTrace}; use crate::traits::{ObligationCause, ObligationCauseCode}; use crate::ty; use crate::ty::error::ExpectedFound; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::util::ppaux::RegionHighlightMode; impl NiceRegionError<'me, 'gcx, 'tcx> { @@ -175,8 +175,8 @@ impl NiceRegionError<'me, 'gcx, 'tcx> { sub_placeholder: Option>, sup_placeholder: Option>, trait_def_id: DefId, - expected_substs: &'tcx Substs<'tcx>, - actual_substs: &'tcx Substs<'tcx>, + expected_substs: SubstsRef<'tcx>, + actual_substs: SubstsRef<'tcx>, ) -> DiagnosticBuilder<'me> { debug!( "try_report_placeholders_trait(\ diff --git a/src/librustc/infer/mod.rs b/src/librustc/infer/mod.rs index ac2ebece442c8..84ad742d3c972 100644 --- a/src/librustc/infer/mod.rs +++ b/src/librustc/infer/mod.rs @@ -18,7 +18,7 @@ use crate::traits::{self, ObligationCause, PredicateObligations, TraitEngine}; use crate::ty::error::{ExpectedFound, TypeError, UnconstrainedNumeric}; use crate::ty::fold::TypeFoldable; use crate::ty::relate::RelateResult; -use crate::ty::subst::{Kind, Substs}; +use crate::ty::subst::{Kind, InternalSubsts, SubstsRef}; use crate::ty::{self, GenericParamDefKind, Ty, TyCtxt, CtxtInterners}; use crate::ty::{FloatVid, IntVid, TyVid}; use crate::util::nodemap::FxHashMap; @@ -1088,8 +1088,8 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { /// Given a set of generics defined on a type or impl, returns a substitution mapping each /// type/region parameter to a fresh inference variable. - pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> &'tcx Substs<'tcx> { - Substs::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param)) + pub fn fresh_substs_for_item(&self, span: Span, def_id: DefId) -> SubstsRef<'tcx> { + InternalSubsts::for_item(self.tcx, def_id, |param, _| self.var_for_def(span, param)) } /// Returns `true` if errors have been reported since this infcx was diff --git a/src/librustc/infer/opaque_types/mod.rs b/src/librustc/infer/opaque_types/mod.rs index e75446b01c11e..159bc1ceae26c 100644 --- a/src/librustc/infer/opaque_types/mod.rs +++ b/src/librustc/infer/opaque_types/mod.rs @@ -9,7 +9,7 @@ use crate::traits::{self, PredicateObligation}; use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind}; use crate::ty::fold::{BottomUpFolder, TypeFoldable, TypeFolder}; use crate::ty::outlives::Component; -use crate::ty::subst::{Kind, Substs, UnpackedKind}; +use crate::ty::subst::{Kind, InternalSubsts, SubstsRef, UnpackedKind}; use crate::util::nodemap::DefIdMap; pub type OpaqueTypeMap<'tcx> = DefIdMap>; @@ -30,7 +30,7 @@ pub struct OpaqueTypeDecl<'tcx> { /// fn foo<'a, 'b, T>() -> Foo<'a, T> /// /// then `substs` would be `['a, T]`. - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, /// The type variable that represents the value of the abstract type /// that we require. In other words, after we compile this function, @@ -437,7 +437,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { // lifetimes with 'static and remapping only those used in the // `impl Trait` return type, resulting in the parameters // shifting. - let id_substs = Substs::identity_for_item(gcx, def_id); + let id_substs = InternalSubsts::identity_for_item(gcx, def_id); let map: FxHashMap, Kind<'gcx>> = opaque_defn .substs .iter() @@ -740,7 +740,7 @@ impl<'a, 'gcx, 'tcx> Instantiator<'a, 'gcx, 'tcx> { &mut self, ty: Ty<'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> Ty<'tcx> { let infcx = self.infcx; let tcx = infcx.tcx; diff --git a/src/librustc/infer/outlives/verify.rs b/src/librustc/infer/outlives/verify.rs index 494f708c6a7b7..e1ad5aeea19fc 100644 --- a/src/librustc/infer/outlives/verify.rs +++ b/src/librustc/infer/outlives/verify.rs @@ -2,7 +2,7 @@ use crate::hir::def_id::DefId; use crate::infer::outlives::env::RegionBoundPairs; use crate::infer::{GenericKind, VerifyBound}; use crate::traits; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts}; use crate::ty::{self, Ty, TyCtxt}; use crate::util::captures::Captures; @@ -292,7 +292,7 @@ impl<'cx, 'gcx, 'tcx> VerifyBoundCx<'cx, 'gcx, 'tcx> { .iter() .map(|(p, _)| *p) .collect(); - let identity_substs = Substs::identity_for_item(tcx, assoc_item_def_id); + let identity_substs = InternalSubsts::identity_for_item(tcx, assoc_item_def_id); let identity_proj = tcx.mk_projection(assoc_item_def_id, identity_substs); self.collect_outlives_from_predicate_list( move |ty| ty == identity_proj, diff --git a/src/librustc/lint/mod.rs b/src/librustc/lint/mod.rs index 6c60f3f5a80a3..dd003e44bea09 100644 --- a/src/librustc/lint/mod.rs +++ b/src/librustc/lint/mod.rs @@ -723,7 +723,7 @@ fn lint_levels<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum) }; let krate = tcx.hir().krate(); - builder.with_lint_attrs(ast::CRATE_NODE_ID, &krate.attrs, |builder| { + builder.with_lint_attrs(hir::CRATE_HIR_ID, &krate.attrs, |builder| { intravisit::walk_crate(builder, krate); }); @@ -737,13 +737,13 @@ struct LintLevelMapBuilder<'a, 'tcx: 'a> { impl<'a, 'tcx> LintLevelMapBuilder<'a, 'tcx> { fn with_lint_attrs(&mut self, - id: ast::NodeId, + id: hir::HirId, attrs: &[ast::Attribute], f: F) where F: FnOnce(&mut Self) { let push = self.levels.push(attrs); - self.levels.register_id(self.tcx.hir().definitions().node_to_hir_id(id)); + self.levels.register_id(id); f(self); self.levels.pop(push); } @@ -755,25 +755,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> { } fn visit_item(&mut self, it: &'tcx hir::Item) { - self.with_lint_attrs(it.id, &it.attrs, |builder| { + self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_item(builder, it); }); } fn visit_foreign_item(&mut self, it: &'tcx hir::ForeignItem) { - self.with_lint_attrs(it.id, &it.attrs, |builder| { + self.with_lint_attrs(it.hir_id, &it.attrs, |builder| { intravisit::walk_foreign_item(builder, it); }) } fn visit_expr(&mut self, e: &'tcx hir::Expr) { - self.with_lint_attrs(e.id, &e.attrs, |builder| { + self.with_lint_attrs(e.hir_id, &e.attrs, |builder| { intravisit::walk_expr(builder, e); }) } fn visit_struct_field(&mut self, s: &'tcx hir::StructField) { - self.with_lint_attrs(s.id, &s.attrs, |builder| { + self.with_lint_attrs(s.hir_id, &s.attrs, |builder| { intravisit::walk_struct_field(builder, s); }) } @@ -782,25 +782,25 @@ impl<'a, 'tcx> intravisit::Visitor<'tcx> for LintLevelMapBuilder<'a, 'tcx> { v: &'tcx hir::Variant, g: &'tcx hir::Generics, item_id: hir::HirId) { - self.with_lint_attrs(v.node.data.id(), &v.node.attrs, |builder| { + self.with_lint_attrs(v.node.data.hir_id(), &v.node.attrs, |builder| { intravisit::walk_variant(builder, v, g, item_id); }) } fn visit_local(&mut self, l: &'tcx hir::Local) { - self.with_lint_attrs(l.id, &l.attrs, |builder| { + self.with_lint_attrs(l.hir_id, &l.attrs, |builder| { intravisit::walk_local(builder, l); }) } fn visit_trait_item(&mut self, trait_item: &'tcx hir::TraitItem) { - self.with_lint_attrs(trait_item.id, &trait_item.attrs, |builder| { + self.with_lint_attrs(trait_item.hir_id, &trait_item.attrs, |builder| { intravisit::walk_trait_item(builder, trait_item); }); } fn visit_impl_item(&mut self, impl_item: &'tcx hir::ImplItem) { - self.with_lint_attrs(impl_item.id, &impl_item.attrs, |builder| { + self.with_lint_attrs(impl_item.hir_id, &impl_item.attrs, |builder| { intravisit::walk_impl_item(builder, impl_item); }); } diff --git a/src/librustc/middle/dead.rs b/src/librustc/middle/dead.rs index 878d93c66cc24..201a779ee1827 100644 --- a/src/librustc/middle/dead.rs +++ b/src/librustc/middle/dead.rs @@ -99,10 +99,10 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { } } - fn handle_field_access(&mut self, lhs: &hir::Expr, node_id: ast::NodeId) { + fn handle_field_access(&mut self, lhs: &hir::Expr, hir_id: hir::HirId) { match self.tables.expr_ty_adjusted(lhs).sty { ty::Adt(def, _) => { - let index = self.tcx.field_index(node_id, self.tables); + let index = self.tcx.field_index(hir_id, self.tables); self.insert_def_id(def.non_enum_variant().fields[index].did); } ty::Tuple(..) => {} @@ -120,7 +120,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { if let PatKind::Wild = pat.node.pat.node { continue; } - let index = self.tcx.field_index(pat.node.id, self.tables); + let index = self.tcx.field_index(pat.node.hir_id, self.tables); self.insert_def_id(variant.fields[index].did); } } @@ -190,7 +190,7 @@ impl<'a, 'tcx> MarkSymbolVisitor<'a, 'tcx> { fn mark_as_used_if_union(&mut self, adt: &ty::AdtDef, fields: &hir::HirVec) { if adt.is_union() && adt.non_enum_variant().fields.len() > 1 && adt.did.is_local() { for field in fields { - let index = self.tcx.field_index(field.id, self.tables); + let index = self.tcx.field_index(field.hir_id, self.tables); self.insert_def_id(adt.non_enum_variant().fields[index].did); } } @@ -232,7 +232,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MarkSymbolVisitor<'a, 'tcx> { self.lookup_and_handle_method(expr.hir_id); } hir::ExprKind::Field(ref lhs, ..) => { - self.handle_field_access(&lhs, expr.id); + self.handle_field_access(&lhs, expr.hir_id); } hir::ExprKind::Struct(_, ref fields, _) => { if let ty::Adt(ref adt, _) = self.tables.expr_ty(expr).sty { diff --git a/src/librustc/middle/exported_symbols.rs b/src/librustc/middle/exported_symbols.rs index 6c43068a22772..32c7216765533 100644 --- a/src/librustc/middle/exported_symbols.rs +++ b/src/librustc/middle/exported_symbols.rs @@ -5,7 +5,7 @@ use rustc_data_structures::stable_hasher::{StableHasher, HashStable, use std::cmp; use std::mem; use crate::ty; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; /// The SymbolExportLevel of a symbols specifies from which kinds of crates /// the symbol will be exported. `C` symbols will be exported from any @@ -33,7 +33,7 @@ impl SymbolExportLevel { #[derive(Eq, PartialEq, Debug, Copy, Clone, RustcEncodable, RustcDecodable)] pub enum ExportedSymbol<'tcx> { NonGeneric(DefId), - Generic(DefId, &'tcx Substs<'tcx>), + Generic(DefId, SubstsRef<'tcx>), NoDefId(ty::SymbolName), } diff --git a/src/librustc/middle/expr_use_visitor.rs b/src/librustc/middle/expr_use_visitor.rs index 8da20ba426663..7fc01e302a7d2 100644 --- a/src/librustc/middle/expr_use_visitor.rs +++ b/src/librustc/middle/expr_use_visitor.rs @@ -33,7 +33,7 @@ pub trait Delegate<'tcx> { // The value found at `cmt` is either copied or moved, depending // on mode. fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: ConsumeMode); @@ -65,7 +65,7 @@ pub trait Delegate<'tcx> { // The value found at `borrow` is being borrowed at the point // `borrow_id` for the region `loan_region` with kind `bk`. fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, @@ -79,7 +79,7 @@ pub trait Delegate<'tcx> { // The path at `cmt` is being assigned to. fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, mode: MutateMode); @@ -329,7 +329,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } fn delegate_consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>) { debug!("delegate_consume(consume_id={}, cmt={:?})", @@ -349,7 +349,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { debug!("consume_expr(expr={:?})", expr); let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate_consume(expr.id, expr.span, &cmt); + self.delegate_consume(expr.hir_id, expr.span, &cmt); self.walk_expr(expr); } @@ -359,7 +359,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr: &hir::Expr, mode: MutateMode) { let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate.mutate(assignment_expr.id, span, &cmt, mode); + self.delegate.mutate(assignment_expr.hir_id, span, &cmt, mode); self.walk_expr(expr); } @@ -372,7 +372,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr, r, bk); let cmt = return_if_err!(self.mc.cat_expr(expr)); - self.delegate.borrow(expr.id, expr.span, &cmt, r, bk, cause); + self.delegate.borrow(expr.hir_id, expr.span, &cmt, r, bk, cause); self.walk_expr(expr) } @@ -629,7 +629,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { /// Indicates that the value of `blk` will be consumed, meaning either copied or moved /// depending on its type. fn walk_block(&mut self, blk: &hir::Block) { - debug!("walk_block(blk.id={})", blk.id); + debug!("walk_block(blk.hir_id={})", blk.hir_id); for stmt in &blk.stmts { self.walk_stmt(stmt); @@ -662,7 +662,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // Consume those fields of the with expression that are needed. for (f_index, with_field) in adt.non_enum_variant().fields.iter().enumerate() { let is_mentioned = fields.iter().any(|f| { - self.tcx().field_index(f.id, self.mc.tables) == f_index + self.tcx().field_index(f.hir_id, self.mc.tables) == f_index }); if !is_mentioned { let cmt_field = self.mc.cat_field( @@ -672,7 +672,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { with_field.ident, with_field.ty(self.tcx(), substs) ); - self.delegate_consume(with_expr.id, with_expr.span, &cmt_field); + self.delegate_consume(with_expr.hir_id, with_expr.span, &cmt_field); } } } @@ -711,7 +711,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { adjustment::Adjust::Unsize => { // Creating a closure/fn-pointer or unsizing consumes // the input and stores it into the resulting rvalue. - self.delegate_consume(expr.id, expr.span, &cmt); + self.delegate_consume(expr.hir_id, expr.span, &cmt); } adjustment::Adjust::Deref(None) => {} @@ -723,7 +723,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // this is an autoref of `x`. adjustment::Adjust::Deref(Some(ref deref)) => { let bk = ty::BorrowKind::from_mutbl(deref.mutbl); - self.delegate.borrow(expr.id, expr.span, &cmt, deref.region, bk, AutoRef); + self.delegate.borrow(expr.hir_id, expr.span, &cmt, deref.region, bk, AutoRef); } adjustment::Adjust::Borrow(ref autoref) => { @@ -741,14 +741,14 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { expr: &hir::Expr, cmt_base: &mc::cmt_<'tcx>, autoref: &adjustment::AutoBorrow<'tcx>) { - debug!("walk_autoref(expr.id={} cmt_base={:?} autoref={:?})", - expr.id, + debug!("walk_autoref(expr.hir_id={} cmt_base={:?} autoref={:?})", + expr.hir_id, cmt_base, autoref); match *autoref { adjustment::AutoBorrow::Ref(r, m) => { - self.delegate.borrow(expr.id, + self.delegate.borrow(expr.hir_id, expr.span, cmt_base, r, @@ -757,8 +757,8 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { } adjustment::AutoBorrow::RawPtr(m) => { - debug!("walk_autoref: expr.id={} cmt_base={:?}", - expr.id, + debug!("walk_autoref: expr.hir_id={} cmt_base={:?}", + expr.hir_id, cmt_base); // Converting from a &T to *T (or &mut T to *mut T) is @@ -770,7 +770,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { data: region::ScopeData::Node })); - self.delegate.borrow(expr.id, + self.delegate.borrow(expr.hir_id, expr.span, cmt_base, r, @@ -864,7 +864,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { // binding being produced. let def = Def::Local(canonical_id); if let Ok(ref binding_cmt) = mc.cat_def(pat.hir_id, pat.span, pat_ty, def) { - delegate.mutate(pat.id, pat.span, binding_cmt, MutateMode::Init); + delegate.mutate(pat.hir_id, pat.span, binding_cmt, MutateMode::Init); } // It is also a borrow or copy/move of the value being matched. @@ -872,7 +872,7 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { ty::BindByReference(m) => { if let ty::Ref(r, _, _) = pat_ty.sty { let bk = ty::BorrowKind::from_mutbl(m); - delegate.borrow(pat.id, pat.span, &cmt_pat, r, bk, RefBinding); + delegate.borrow(pat.hir_id, pat.span, &cmt_pat, r, bk, RefBinding); } } ty::BindByValue(..) => { @@ -920,10 +920,11 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { fn walk_captures(&mut self, closure_expr: &hir::Expr, fn_decl_span: Span) { debug!("walk_captures({:?})", closure_expr); - self.tcx().with_freevars(closure_expr.id, |freevars| { + let closure_node_id = self.tcx().hir().hir_to_node_id(closure_expr.hir_id); + let closure_def_id = self.tcx().hir().local_def_id(closure_node_id); + self.tcx().with_freevars(closure_node_id, |freevars| { for freevar in freevars { let var_hir_id = self.tcx().hir().node_to_hir_id(freevar.var_id()); - let closure_def_id = self.tcx().hir().local_def_id(closure_expr.id); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, closure_expr_id: closure_def_id.to_local(), @@ -938,10 +939,10 @@ impl<'a, 'gcx, 'tcx> ExprUseVisitor<'a, 'gcx, 'tcx> { self.param_env, &cmt_var, CaptureMove); - self.delegate.consume(closure_expr.id, freevar.span, &cmt_var, mode); + self.delegate.consume(closure_expr.hir_id, freevar.span, &cmt_var, mode); } ty::UpvarCapture::ByRef(upvar_borrow) => { - self.delegate.borrow(closure_expr.id, + self.delegate.borrow(closure_expr.hir_id, fn_decl_span, &cmt_var, upvar_borrow.region, diff --git a/src/librustc/middle/liveness.rs b/src/librustc/middle/liveness.rs index 03e16494b0386..76933a6e3484b 100644 --- a/src/librustc/middle/liveness.rs +++ b/src/librustc/middle/liveness.rs @@ -265,7 +265,7 @@ struct IrMaps<'a, 'tcx: 'a> { num_vars: usize, live_node_map: HirIdMap, variable_map: HirIdMap, - capture_info_map: NodeMap>>, + capture_info_map: HirIdMap>>, var_kinds: Vec, lnks: Vec, } @@ -344,8 +344,8 @@ impl<'a, 'tcx> IrMaps<'a, 'tcx> { } } - fn set_captures(&mut self, node_id: NodeId, cs: Vec) { - self.capture_info_map.insert(node_id, Rc::new(cs)); + fn set_captures(&mut self, hir_id: HirId, cs: Vec) { + self.capture_info_map.insert(hir_id, Rc::new(cs)); } fn lnk(&self, ln: LiveNode) -> LiveNodeKind { @@ -460,7 +460,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) { match expr.node { // live nodes required for uses or definitions of variables: hir::ExprKind::Path(hir::QPath::Resolved(_, ref path)) => { - debug!("expr {}: path that leads to {:?}", expr.id, path.def); + debug!("expr {}: path that leads to {:?}", expr.hir_id, path.def); if let Def::Local(..) = path.def { ir.add_live_node_for_node(expr.hir_id, ExprNode(expr.span)); } @@ -476,7 +476,8 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) { // in better error messages than just pointing at the closure // construction site. let mut call_caps = Vec::new(); - ir.tcx.with_freevars(expr.id, |freevars| { + let node_id = ir.tcx.hir().hir_to_node_id(expr.hir_id); + ir.tcx.with_freevars(node_id, |freevars| { call_caps.extend(freevars.iter().filter_map(|fv| { if let Def::Local(rv) = fv.def { let fv_ln = ir.add_live_node(FreeVarNode(fv.span)); @@ -487,7 +488,7 @@ fn visit_expr<'a, 'tcx>(ir: &mut IrMaps<'a, 'tcx>, expr: &'tcx Expr) { } })); }); - ir.set_captures(expr.id, call_caps); + ir.set_captures(expr.hir_id, call_caps); intravisit::walk_expr(ir, expr); } @@ -925,7 +926,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } fn compute(&mut self, body: &hir::Expr) -> LiveNode { - debug!("compute: using id for body, {}", self.ir.tcx.hir().node_to_pretty_string(body.id)); + debug!("compute: using id for body, {}", + self.ir.tcx.hir().hir_to_pretty_string(body.hir_id)); // the fallthrough exit is only for those cases where we do not // explicitly return: @@ -940,7 +942,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { for ln_idx in 0..self.ir.num_live_nodes { debug!("{:?}", self.ln_str(LiveNode(ln_idx as u32))); } - body.id + body.hir_id }, entry_ln); @@ -950,7 +952,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_block(&mut self, blk: &hir::Block, succ: LiveNode) -> LiveNode { if blk.targeted_by_break { - self.break_ln.insert(blk.id, succ); + let node_id = self.ir.tcx.hir().hir_to_node_id(blk.hir_id); + self.break_ln.insert(node_id, succ); } let succ = self.propagate_through_opt_expr(blk.expr.as_ref().map(|e| &**e), succ); blk.stmts.iter().rev().fold(succ, |succ, stmt| { @@ -1002,7 +1005,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { fn propagate_through_expr(&mut self, expr: &Expr, succ: LiveNode) -> LiveNode { - debug!("propagate_through_expr: {}", self.ir.tcx.hir().node_to_pretty_string(expr.id)); + debug!("propagate_through_expr: {}", self.ir.tcx.hir().hir_to_pretty_string(expr.hir_id)); match expr.node { // Interesting cases with control flow or which gen/kill @@ -1016,11 +1019,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { hir::ExprKind::Closure(..) => { debug!("{} is an ExprKind::Closure", - self.ir.tcx.hir().node_to_pretty_string(expr.id)); + self.ir.tcx.hir().hir_to_pretty_string(expr.hir_id)); // the construction of a closure itself is not important, // but we have to consider the closed over variables. - let caps = self.ir.capture_info_map.get(&expr.id).cloned().unwrap_or_else(|| + let caps = self.ir.capture_info_map.get(&expr.hir_id).cloned().unwrap_or_else(|| span_bug!(expr.span, "no registered caps")); caps.iter().rev().fold(succ, |succ, cap| { @@ -1169,7 +1172,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::Call(ref f, ref args) => { - let m = self.ir.tcx.hir().get_module_parent(expr.id); + let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1180,7 +1183,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } hir::ExprKind::MethodCall(.., ref args) => { - let m = self.ir.tcx.hir().get_module_parent(expr.id); + let m = self.ir.tcx.hir().get_module_parent_by_hir_id(expr.hir_id); let succ = if self.ir.tcx.is_ty_uninhabited_from(m, self.tables.expr_ty(expr)) { self.s.exit_ln } else { @@ -1386,17 +1389,17 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> { } } debug!("propagate_through_loop: using id for loop body {} {}", - expr.id, self.ir.tcx.hir().node_to_pretty_string(body.id)); + expr.hir_id, self.ir.tcx.hir().hir_to_pretty_string(body.hir_id)); - - self.break_ln.insert(expr.id, succ); + let node_id = self.ir.tcx.hir().hir_to_node_id(expr.hir_id); + self.break_ln.insert(node_id, succ); let cond_ln = match kind { LoopLoop => ln, WhileLoop(ref cond) => self.propagate_through_expr(&cond, ln), }; - self.cont_ln.insert(expr.id, cond_ln); + self.cont_ln.insert(node_id, cond_ln); let body_ln = self.propagate_through_block(body, cond_ln); diff --git a/src/librustc/middle/mem_categorization.rs b/src/librustc/middle/mem_categorization.rs index f65c09e31343c..822a42b374f38 100644 --- a/src/librustc/middle/mem_categorization.rs +++ b/src/librustc/middle/mem_categorization.rs @@ -632,7 +632,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { } pub fn cat_expr_unadjusted(&self, expr: &hir::Expr) -> McResult> { - debug!("cat_expr: id={} expr={:?}", expr.id, expr); + debug!("cat_expr: id={} expr={:?}", expr.hir_id, expr); let expr_ty = self.expr_ty(expr)?; match expr.node { @@ -648,10 +648,10 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { hir::ExprKind::Field(ref base, f_ident) => { let base_cmt = Rc::new(self.cat_expr(&base)?); debug!("cat_expr(cat_field): id={} expr={:?} base={:?}", - expr.id, + expr.hir_id, expr, base_cmt); - let f_index = self.tcx.field_index(expr.id, self.tables); + let f_index = self.tcx.field_index(expr.hir_id, self.tables); Ok(self.cat_field(expr, base_cmt, f_index, f_ident, expr_ty)) } @@ -1321,7 +1321,7 @@ impl<'a, 'gcx, 'tcx> MemCategorizationContext<'a, 'gcx, 'tcx> { for fp in field_pats { let field_ty = self.pat_ty_adjusted(&fp.node.pat)?; // see (*2) - let f_index = self.tcx.field_index(fp.node.id, self.tables); + let f_index = self.tcx.field_index(fp.node.hir_id, self.tables); let cmt_field = Rc::new(self.cat_field(pat, cmt.clone(), f_index, fp.node.ident, field_ty)); self.cat_pattern_(cmt_field, &fp.node.pat, op)?; diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index fd188b33d7e1f..3499138fb7915 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -745,7 +745,7 @@ fn record_var_lifetime(visitor: &mut RegionResolutionVisitor<'_, '_>, } fn resolve_block<'a, 'tcx>(visitor: &mut RegionResolutionVisitor<'a, 'tcx>, blk: &'tcx hir::Block) { - debug!("resolve_block(blk.id={:?})", blk.id); + debug!("resolve_block(blk.hir_id={:?})", blk.hir_id); let prev_cx = visitor.cx; diff --git a/src/librustc/middle/resolve_lifetime.rs b/src/librustc/middle/resolve_lifetime.rs index 08da74f47d450..832391d44162b 100644 --- a/src/librustc/middle/resolve_lifetime.rs +++ b/src/librustc/middle/resolve_lifetime.rs @@ -13,7 +13,7 @@ use crate::ty::{self, DefIdTree, GenericParamDefKind, TyCtxt}; use crate::rustc::lint; use crate::session::Session; -use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, NodeMap, NodeSet}; +use crate::util::nodemap::{DefIdMap, FxHashMap, FxHashSet, HirIdMap, HirIdSet, NodeMap}; use errors::{Applicability, DiagnosticBuilder}; use rustc_data_structures::sync::Lrc; use std::borrow::Cow; @@ -83,7 +83,7 @@ impl Region { fn early(hir_map: &Map<'_>, index: &mut u32, param: &GenericParam) -> (ParamName, Region) { let i = *index; *index += 1; - let def_id = hir_map.local_def_id(param.id); + let def_id = hir_map.local_def_id_from_hir_id(param.hir_id); let origin = LifetimeDefOrigin::from_param(param); debug!("Region::early: index={} def_id={:?}", i, def_id); (param.name.modern(), Region::EarlyBound(i, def_id, origin)) @@ -91,7 +91,7 @@ impl Region { fn late(hir_map: &Map<'_>, param: &GenericParam) -> (ParamName, Region) { let depth = ty::INNERMOST; - let def_id = hir_map.local_def_id(param.id); + let def_id = hir_map.local_def_id_from_hir_id(param.hir_id); let origin = LifetimeDefOrigin::from_param(param); debug!( "Region::late: param={:?} depth={:?} def_id={:?} origin={:?}", @@ -151,7 +151,7 @@ impl Region { if let Region::EarlyBound(index, _, _) = self { params .nth(index as usize) - .and_then(|lifetime| map.defs.get(&lifetime.id).cloned()) + .and_then(|lifetime| map.defs.get(&lifetime.hir_id).cloned()) } else { Some(self) } @@ -195,12 +195,12 @@ pub type ObjectLifetimeDefault = Set1; struct NamedRegionMap { // maps from every use of a named (not anonymous) lifetime to a // `Region` describing how that region is bound - pub defs: NodeMap, + pub defs: HirIdMap, // the set of lifetime def ids that are late-bound; a region can // be late-bound if (a) it does NOT appear in a where-clause and // (b) it DOES appear in the arguments. - pub late_bound: NodeSet, + pub late_bound: HirIdSet, // For each type and trait definition, maps type parameters // to the trait object lifetime defaults computed from them. @@ -385,13 +385,11 @@ fn resolve_lifetimes<'tcx>( let mut rl = ResolveLifetimes::default(); - for (k, v) in named_region_map.defs { - let hir_id = tcx.hir().node_to_hir_id(k); + for (hir_id, v) in named_region_map.defs { let map = rl.defs.entry(hir_id.owner_local_def_id()).or_default(); Lrc::get_mut(map).unwrap().insert(hir_id.local_id, v); } - for k in named_region_map.late_bound { - let hir_id = tcx.hir().node_to_hir_id(k); + for hir_id in named_region_map.late_bound { let map = rl.late_bound .entry(hir_id.owner_local_def_id()) .or_default(); @@ -570,7 +568,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { } fn visit_ty(&mut self, ty: &'tcx hir::Ty) { - debug!("visit_ty: id={:?} ty={:?}", ty.id, ty); + debug!("visit_ty: id={:?} ty={:?}", ty.hir_id, ty); match ty.node { hir::TyKind::BareFn(ref c) => { let next_early_index = self.next_early_index(); @@ -629,7 +627,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { hir::TyKind::Rptr(ref lifetime_ref, ref mt) => { self.visit_lifetime(lifetime_ref); let scope = Scope::ObjectLifetimeDefault { - lifetime: self.map.defs.get(&lifetime_ref.id).cloned(), + lifetime: self.map.defs.get(&lifetime_ref.hir_id).cloned(), s: self.scope, }; self.with(scope, |_, this| this.visit_ty(&mt.ty)); @@ -672,7 +670,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> { // and ban them. Type variables instantiated inside binders aren't // well-supported at the moment, so this doesn't work. // In the future, this should be fixed and this error should be removed. - let def = self.map.defs.get(&lifetime.id).cloned(); + let def = self.map.defs.get(&lifetime.hir_id).cloned(); if let Some(Region::LateBound(_, def_id, _)) = def { if let Some(node_id) = self.tcx.hir().as_local_node_id(def_id) { // Ensure that the parent of the def is an item, not HRTB @@ -766,6 +764,13 @@ 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), } } @@ -1339,7 +1344,7 @@ fn object_lifetime_defaults_for_item( add_bounds(&mut set, ¶m.bounds); - let param_def_id = tcx.hir().local_def_id(param.id); + let param_def_id = tcx.hir().local_def_id_from_hir_id(param.hir_id); for predicate in &generics.where_clause.predicates { // Look for `type: ...` where clauses. let data = match *predicate { @@ -1374,7 +1379,7 @@ fn object_lifetime_defaults_for_item( .iter() .filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => Some(( - param.id, + param.hir_id, hir::LifetimeName::Param(param.name), LifetimeDefOrigin::from_param(param), )), @@ -1383,7 +1388,7 @@ fn object_lifetime_defaults_for_item( .enumerate() .find(|&(_, (_, lt_name, _))| lt_name == name) .map_or(Set1::Many, |(i, (id, _, origin))| { - let def_id = tcx.hir().local_def_id(id); + let def_id = tcx.hir().local_def_id_from_hir_id(id); Set1::One(Region::EarlyBound(i as u32, def_id, origin)) }) } @@ -1501,8 +1506,10 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } } }; - if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get(lifetime.id) { - if let Some(parent) = self.tcx.hir().find(self.tcx.hir().get_parent(hir_lifetime.id)) { + if let Node::Lifetime(hir_lifetime) = self.tcx.hir().get_by_hir_id(lifetime.hir_id) { + if let Some(parent) = self.tcx.hir().find_by_hir_id( + self.tcx.hir().get_parent_item(hir_lifetime.hir_id)) + { match parent { Node::Item(item) => { if let hir::ItemKind::Fn(decl, _, _, _) = &item.node { @@ -1582,22 +1589,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!("node id first={:?}", node_id); if let Some((id, span, name)) = match self.tcx.hir().get(node_id) { Node::Lifetime(hir_lifetime) => Some(( - hir_lifetime.id, + hir_lifetime.hir_id, hir_lifetime.span, hir_lifetime.name.ident(), )), Node::GenericParam(param) => { - Some((param.id, param.span, param.name.ident())) + Some((param.hir_id, param.span, param.name.ident())) } _ => None, } { - debug!("id = {:?} span = {:?} name = {:?}", node_id, span, name); + debug!("id = {:?} span = {:?} name = {:?}", id, span, name); if name == keywords::UnderscoreLifetime.ident() { continue; } - let mut err = self.tcx.struct_span_lint_node( + let mut err = self.tcx.struct_span_lint_hir( lint::builtin::SINGLE_USE_LIFETIMES, id, span, @@ -1622,17 +1629,17 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let node_id = self.tcx.hir().as_local_node_id(def_id).unwrap(); if let Some((id, span, name)) = match self.tcx.hir().get(node_id) { Node::Lifetime(hir_lifetime) => Some(( - hir_lifetime.id, + hir_lifetime.hir_id, hir_lifetime.span, hir_lifetime.name.ident(), )), Node::GenericParam(param) => { - Some((param.id, param.span, param.name.ident())) + Some((param.hir_id, param.span, param.name.ident())) } _ => None, } { - debug!("id ={:?} span = {:?} name = {:?}", node_id, span, name); - let mut err = self.tcx.struct_span_lint_node( + debug!("id ={:?} span = {:?} name = {:?}", id, span, name); + let mut err = self.tcx.struct_span_lint_hir( lint::builtin::UNUSED_LIFETIMES, id, span, @@ -1706,7 +1713,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { let mut non_lifetime_count = 0; let lifetimes = generics.params.iter().filter_map(|param| match param.kind { GenericParamKind::Lifetime { .. } => { - if self.map.late_bound.contains(¶m.id) { + if self.map.late_bound.contains(¶m.hir_id) { Some(Region::late(&self.tcx.hir(), param)) } else { Some(Region::early(&self.tcx.hir(), &mut index, param)) @@ -2049,8 +2056,8 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { // and whether there's a `self` argument (treated specially). let mut assoc_item_kind = None; let mut impl_self = None; - let parent = self.tcx.hir().get_parent_node(output.id); - let body = match self.tcx.hir().get(parent) { + let parent = self.tcx.hir().get_parent_node_by_hir_id(output.hir_id); + let body = match self.tcx.hir().get_by_hir_id(parent) { // `fn` definitions and methods. Node::Item(&hir::Item { node: hir::ItemKind::Fn(.., body), @@ -2063,12 +2070,13 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Trait(.., ref trait_items) = self.tcx .hir() - .expect_item(self.tcx.hir().get_parent(parent)) + .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) .node { + let parent_node_id = self.tcx.hir().hir_to_node_id(parent); assoc_item_kind = trait_items .iter() - .find(|ti| ti.id.node_id == parent) + .find(|ti| ti.id.node_id == parent_node_id) .map(|ti| ti.kind); } match *m { @@ -2083,13 +2091,14 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { }) => { if let hir::ItemKind::Impl(.., ref self_ty, ref impl_items) = self.tcx .hir() - .expect_item(self.tcx.hir().get_parent(parent)) + .expect_item_by_hir_id(self.tcx.hir().get_parent_item(parent)) .node { impl_self = Some(self_ty); + let parent_node_id = self.tcx.hir().hir_to_node_id(parent); assoc_item_kind = impl_items .iter() - .find(|ii| ii.id.node_id == parent) + .find(|ii| ii.id.node_id == parent_node_id) .map(|ii| ii.kind); } Some(body) @@ -2143,7 +2152,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let hir::TyKind::Rptr(lifetime_ref, ref mt) = inputs[0].node { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = mt.ty.node { if is_self_ty(path.def) { - if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) { + if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) { let scope = Scope::Elision { elide: Elide::Exact(lifetime), s: self.scope, @@ -2223,18 +2232,22 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { if let hir::TyKind::BareFn(_) = ty.node { self.outer_index.shift_in(1); } - if let hir::TyKind::TraitObject(ref bounds, ref lifetime) = ty.node { - for bound in bounds { - self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None); - } + match ty.node { + hir::TyKind::TraitObject(ref bounds, ref lifetime) => { + for bound in bounds { + self.visit_poly_trait_ref(bound, hir::TraitBoundModifier::None); + } - // Stay on the safe side and don't include the object - // lifetime default (which may not end up being used). - if !lifetime.is_elided() { - self.visit_lifetime(lifetime); + // Stay on the safe side and don't include the object + // lifetime default (which may not end up being used). + if !lifetime.is_elided() { + self.visit_lifetime(lifetime); + } + } + hir::TyKind::CVarArgs(_) => {} + _ => { + intravisit::walk_ty(self, ty); } - } else { - intravisit::walk_ty(self, ty); } if let hir::TyKind::BareFn(_) = ty.node { self.outer_index.shift_out(1); @@ -2262,7 +2275,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn visit_lifetime(&mut self, lifetime_ref: &hir::Lifetime) { - if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.id) { + if let Some(&lifetime) = self.map.defs.get(&lifetime_ref.hir_id) { match lifetime { Region::LateBound(debruijn, _, _) | Region::LateBoundAnon(debruijn, _) if debruijn < self.outer_index => @@ -2653,7 +2666,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { } fn insert_lifetime(&mut self, lifetime_ref: &'tcx hir::Lifetime, def: Region) { - if lifetime_ref.id == ast::DUMMY_NODE_ID { + if lifetime_ref.hir_id == hir::DUMMY_HIR_ID { span_bug!( lifetime_ref.span, "lifetime reference not renumbered, \ @@ -2663,11 +2676,11 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { debug!( "insert_lifetime: {} resolved to {:?} span={:?}", - self.tcx.hir().node_to_string(lifetime_ref.id), + self.tcx.hir().hir_to_string(lifetime_ref.hir_id), def, self.tcx.sess.source_map().span_to_string(lifetime_ref.span) ); - self.map.defs.insert(lifetime_ref.id, def); + self.map.defs.insert(lifetime_ref.hir_id, def); match def { Region::LateBoundAnon(..) | Region::Static => { @@ -2699,7 +2712,7 @@ impl<'a, 'tcx> LifetimeContext<'a, 'tcx> { /// error (esp. around impl trait). In that case, we remove the /// entry into `map.defs` so as not to confuse later code. fn uninsert_lifetime_on_error(&mut self, lifetime_ref: &'tcx hir::Lifetime, bad_def: Region) { - let old_value = self.map.defs.remove(&lifetime_ref.id); + let old_value = self.map.defs.remove(&lifetime_ref.hir_id); assert_eq!(old_value, Some(bad_def)); } } @@ -2789,11 +2802,11 @@ fn insert_late_bound_lifetimes( debug!( "insert_late_bound_lifetimes: lifetime {:?} with id {:?} is late-bound", param.name.ident(), - param.id + param.hir_id ); - let inserted = map.late_bound.insert(param.id); - assert!(inserted, "visited lifetime {:?} twice", param.id); + let inserted = map.late_bound.insert(param.hir_id); + assert!(inserted, "visited lifetime {:?} twice", param.hir_id); } return; diff --git a/src/librustc/middle/stability.rs b/src/librustc/middle/stability.rs index 707d3484982ed..f85b80605449b 100644 --- a/src/librustc/middle/stability.rs +++ b/src/librustc/middle/stability.rs @@ -14,7 +14,7 @@ use crate::session::{DiagnosticMessageId, Session}; use syntax::symbol::Symbol; use syntax_pos::{Span, MultiSpan}; use syntax::ast; -use syntax::ast::{NodeId, Attribute}; +use syntax::ast::Attribute; use syntax::errors::Applicability; use syntax::feature_gate::{GateIssue, emit_feature_err}; use syntax::attr::{self, Stability, Deprecation}; @@ -117,13 +117,13 @@ struct Annotator<'a, 'tcx: 'a> { impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { // Determine the stability for a node based on its attributes and inherited // stability. The stability is recorded in the index and used as the parent. - fn annotate(&mut self, id: NodeId, attrs: &[Attribute], + fn annotate(&mut self, hir_id: HirId, attrs: &[Attribute], item_sp: Span, kind: AnnotationKind, visit_children: F) where F: FnOnce(&mut Self) { if self.tcx.features().staged_api { // This crate explicitly wants staged API. - debug!("annotate(id = {:?}, attrs = {:?})", id, attrs); + debug!("annotate(id = {:?}, attrs = {:?})", hir_id, attrs); if let Some(..) = attr::find_deprecation(&self.tcx.sess.parse_sess, attrs, item_sp) { self.tcx.sess.span_err(item_sp, "`#[deprecated]` cannot be used in staged api, \ use `#[rustc_deprecated]` instead"); @@ -178,7 +178,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } } - let hir_id = self.tcx.hir().node_to_hir_id(id); self.index.stab_map.insert(hir_id, stab); let orig_parent_stab = replace(&mut self.parent_stab, Some(stab)); @@ -188,7 +187,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { debug!("annotate: not found, parent = {:?}", self.parent_stab); if let Some(stab) = self.parent_stab { if stab.level.is_unstable() { - let hir_id = self.tcx.hir().node_to_hir_id(id); self.index.stab_map.insert(hir_id, stab); } } @@ -209,7 +207,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { // -Zforce-unstable-if-unmarked is set. if let Some(stab) = self.parent_stab { if stab.level.is_unstable() { - let hir_id = self.tcx.hir().node_to_hir_id(id); self.index.stab_map.insert(hir_id, stab); } } @@ -220,7 +217,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { } // `Deprecation` is just two pointers, no need to intern it - let hir_id = self.tcx.hir().node_to_hir_id(id); let depr_entry = DeprecationEntry::local(depr, hir_id); self.index.depr_map.insert(hir_id, depr_entry.clone()); @@ -229,7 +225,6 @@ impl<'a, 'tcx: 'a> Annotator<'a, 'tcx> { visit_children(self); self.parent_depr = orig_parent_depr; } else if let Some(parent_depr) = self.parent_depr.clone() { - let hir_id = self.tcx.hir().node_to_hir_id(id); self.index.depr_map.insert(hir_id, parent_depr); visit_children(self); } else { @@ -264,20 +259,20 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } hir::ItemKind::Struct(ref sd, _) => { if !sd.is_struct() { - self.annotate(sd.id(), &i.attrs, i.span, AnnotationKind::Required, |_| {}) + self.annotate(sd.hir_id(), &i.attrs, i.span, AnnotationKind::Required, |_| {}) } } _ => {} } - self.annotate(i.id, &i.attrs, i.span, kind, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, kind, |v| { intravisit::walk_item(v, i) }); self.in_trait_impl = orig_in_trait_impl; } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { - self.annotate(ti.id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { + self.annotate(ti.hir_id, &ti.attrs, ti.span, AnnotationKind::Required, |v| { intravisit::walk_trait_item(v, ti); }); } @@ -288,31 +283,30 @@ impl<'a, 'tcx> Visitor<'tcx> for Annotator<'a, 'tcx> { } else { AnnotationKind::Required }; - self.annotate(ii.id, &ii.attrs, ii.span, kind, |v| { + self.annotate(ii.hir_id, &ii.attrs, ii.span, kind, |v| { intravisit::walk_impl_item(v, ii); }); } fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { - self.annotate(var.node.data.id(), &var.node.attrs, var.span, AnnotationKind::Required, |v| { - intravisit::walk_variant(v, var, g, item_id); - }) + self.annotate(var.node.data.hir_id(), &var.node.attrs, var.span, AnnotationKind::Required, + |v| { intravisit::walk_variant(v, var, g, item_id) }) } fn visit_struct_field(&mut self, s: &'tcx StructField) { - self.annotate(s.id, &s.attrs, s.span, AnnotationKind::Required, |v| { + self.annotate(s.hir_id, &s.attrs, s.span, AnnotationKind::Required, |v| { intravisit::walk_struct_field(v, s); }); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { - self.annotate(i.id, &i.attrs, i.span, AnnotationKind::Required, |v| { + self.annotate(i.hir_id, &i.attrs, i.span, AnnotationKind::Required, |v| { intravisit::walk_foreign_item(v, i); }); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { - self.annotate(md.id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); + self.annotate(md.hir_id, &md.attrs, md.span, AnnotationKind::Required, |_| {}); } } @@ -322,12 +316,12 @@ struct MissingStabilityAnnotations<'a, 'tcx: 'a> { } impl<'a, 'tcx: 'a> MissingStabilityAnnotations<'a, 'tcx> { - fn check_missing_stability(&self, id: NodeId, span: Span, name: &str) { - let hir_id = self.tcx.hir().node_to_hir_id(id); + fn check_missing_stability(&self, hir_id: HirId, span: Span, name: &str) { let stab = self.tcx.stability().local_stability(hir_id); + let node_id = self.tcx.hir().hir_to_node_id(hir_id); let is_error = !self.tcx.sess.opts.test && stab.is_none() && - self.access_levels.is_reachable(id); + self.access_levels.is_reachable(node_id); if is_error { self.tcx.sess.span_err( span, @@ -350,42 +344,42 @@ impl<'a, 'tcx> Visitor<'tcx> for MissingStabilityAnnotations<'a, 'tcx> { // optional. They inherit stability from their parents when unannotated. hir::ItemKind::Impl(.., None, _, _) | hir::ItemKind::ForeignMod(..) => {} - _ => self.check_missing_stability(i.id, i.span, i.node.descriptive_variant()) + _ => self.check_missing_stability(i.hir_id, i.span, i.node.descriptive_variant()) } intravisit::walk_item(self, i) } fn visit_trait_item(&mut self, ti: &'tcx hir::TraitItem) { - self.check_missing_stability(ti.id, ti.span, "item"); + self.check_missing_stability(ti.hir_id, ti.span, "item"); intravisit::walk_trait_item(self, ti); } fn visit_impl_item(&mut self, ii: &'tcx hir::ImplItem) { let impl_def_id = self.tcx.hir().local_def_id(self.tcx.hir().get_parent(ii.id)); if self.tcx.impl_trait_ref(impl_def_id).is_none() { - self.check_missing_stability(ii.id, ii.span, "item"); + self.check_missing_stability(ii.hir_id, ii.span, "item"); } intravisit::walk_impl_item(self, ii); } fn visit_variant(&mut self, var: &'tcx Variant, g: &'tcx Generics, item_id: HirId) { - self.check_missing_stability(var.node.data.id(), var.span, "variant"); + self.check_missing_stability(var.node.data.hir_id(), var.span, "variant"); intravisit::walk_variant(self, var, g, item_id); } fn visit_struct_field(&mut self, s: &'tcx StructField) { - self.check_missing_stability(s.id, s.span, "field"); + self.check_missing_stability(s.hir_id, s.span, "field"); intravisit::walk_struct_field(self, s); } fn visit_foreign_item(&mut self, i: &'tcx hir::ForeignItem) { - self.check_missing_stability(i.id, i.span, i.node.descriptive_variant()); + self.check_missing_stability(i.hir_id, i.span, i.node.descriptive_variant()); intravisit::walk_foreign_item(self, i); } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { - self.check_missing_stability(md.id, md.span, "macro"); + self.check_missing_stability(md.hir_id, md.span, "macro"); } } @@ -403,10 +397,14 @@ impl<'a, 'tcx> Index<'tcx> { active_features: Default::default(), }; - let ref active_lib_features = tcx.features().declared_lib_features; + let active_lib_features = &tcx.features().declared_lib_features; + let active_lang_features = &tcx.features().declared_lang_features; - // Put the active features into a map for quick lookup - index.active_features = active_lib_features.iter().map(|&(ref s, _)| s.clone()).collect(); + // Put the active features into a map for quick lookup. + index.active_features = + active_lib_features.iter().map(|&(ref s, ..)| s.clone()) + .chain(active_lang_features.iter().map(|&(ref s, ..)| s.clone())) + .collect(); { let krate = tcx.hir().krate(); @@ -441,7 +439,7 @@ impl<'a, 'tcx> Index<'tcx> { annotator.parent_stab = Some(stability); } - annotator.annotate(ast::CRATE_NODE_ID, + annotator.annotate(hir::CRATE_HIR_ID, &krate.attrs, krate.span, AnnotationKind::Required, @@ -563,9 +561,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// If `id` is `Some(_)`, this function will also check if the item at `def_id` has been /// deprecated. If the item is indeed deprecated, we will emit a deprecation lint attached to /// `id`. - pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { + pub fn eval_stability(self, def_id: DefId, id: Option, span: Span) -> EvalResult { let lint_deprecated = |def_id: DefId, - id: NodeId, + id: HirId, note: Option, suggestion: Option, message: &str, @@ -576,9 +574,9 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { format!("{}", message) }; - let mut diag = self.struct_span_lint_node(lint, id, span, &msg); + let mut diag = self.struct_span_lint_hir(lint, id, span, &msg); if let Some(suggestion) = suggestion { - if let hir::Node::Expr(_) = self.hir().get(id) { + if let hir::Node::Expr(_) = self.hir().get_by_hir_id(id) { diag.span_suggestion( span, &msg, @@ -588,15 +586,16 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } diag.emit(); - if id == ast::DUMMY_NODE_ID { - span_bug!(span, "emitted a {} lint with dummy node id: {:?}", lint.name, def_id); + if id == hir::DUMMY_HIR_ID { + span_bug!(span, "emitted a {} lint with dummy HIR id: {:?}", lint.name, def_id); } }; // Deprecated attributes apply in-crate and cross-crate. if let Some(id) = id { if let Some(depr_entry) = self.lookup_deprecation_entry(def_id) { - let parent_def_id = self.hir().local_def_id(self.hir().get_parent(id)); + let parent_def_id = self.hir().local_def_id_from_hir_id( + self.hir().get_parent_item(id)); let skip = self.lookup_deprecation_entry(parent_def_id) .map_or(false, |parent_depr| parent_depr.same_origin(&depr_entry)); @@ -709,7 +708,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// /// Additionally, this function will also check if the item is deprecated. If so, and `id` is /// not `None`, a deprecated lint attached to `id` will be emitted. - pub fn check_stability(self, def_id: DefId, id: Option, span: Span) { + pub fn check_stability(self, def_id: DefId, id: Option, span: Span) { match self.eval_stability(def_id, id, span) { EvalResult::Allow => {} EvalResult::Deny { feature, reason, issue } => { @@ -769,7 +768,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { None => return, }; let def_id = DefId { krate: cnum, index: CRATE_DEF_INDEX }; - self.tcx.check_stability(def_id, Some(item.id), item.span); + self.tcx.check_stability(def_id, Some(item.hir_id), item.span); } // For implementations of traits, check the stability of each item @@ -817,7 +816,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> { } fn visit_path(&mut self, path: &'tcx hir::Path, id: hir::HirId) { - let id = self.tcx.hir().hir_to_node_id(id); if let Some(def_id) = path.def.opt_def_id() { self.tcx.check_stability(def_id, Some(id), path.span) } @@ -843,7 +841,7 @@ pub fn check_unused_or_stable_features<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) { tcx, access_levels, }; - missing.check_missing_stability(ast::CRATE_NODE_ID, krate.span, "crate"); + missing.check_missing_stability(hir::CRATE_HIR_ID, krate.span, "crate"); intravisit::walk_crate(&mut missing, krate); krate.visit_all_item_likes(&mut missing.as_deep_visitor()); } diff --git a/src/librustc/mir/interpret/error.rs b/src/librustc/mir/interpret/error.rs index 29beabdb2abdf..c4e1860bd8333 100644 --- a/src/librustc/mir/interpret/error.rs +++ b/src/librustc/mir/interpret/error.rs @@ -1,5 +1,6 @@ use std::{fmt, env}; +use crate::hir; use crate::hir::map::definitions::DefPathData; use crate::mir; use crate::ty::{self, Ty, layout}; @@ -14,7 +15,6 @@ use crate::ty::query::TyCtxtAt; use errors::DiagnosticBuilder; use syntax_pos::{Pos, Span}; -use syntax::ast; use syntax::symbol::Symbol; #[derive(Debug, Copy, Clone, PartialEq, Eq)] @@ -50,7 +50,7 @@ pub struct ConstEvalErr<'tcx> { pub struct FrameInfo<'tcx> { pub call_site: Span, // this span is in the caller! pub instance: ty::Instance<'tcx>, - pub lint_root: Option, + pub lint_root: Option, } impl<'tcx> fmt::Display for FrameInfo<'tcx> { @@ -98,7 +98,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { pub fn report_as_lint(&self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, - lint_root: ast::NodeId, + lint_root: hir::HirId, ) -> ErrorHandled { let lint = self.struct_generic( tcx, @@ -118,7 +118,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { &self, tcx: TyCtxtAt<'a, 'gcx, 'tcx>, message: &str, - lint_root: Option, + lint_root: Option, ) -> Result, ErrorHandled> { match self.error { EvalErrorKind::Layout(LayoutError::Unknown(_)) | @@ -129,15 +129,15 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> { } trace!("reporting const eval failure at {:?}", self.span); let mut err = if let Some(lint_root) = lint_root { - let node_id = self.stacktrace + let hir_id = self.stacktrace .iter() .rev() .filter_map(|frame| frame.lint_root) .next() .unwrap_or(lint_root); - tcx.struct_span_lint_node( + tcx.struct_span_lint_hir( crate::rustc::lint::builtin::CONST_ERR, - node_id, + hir_id, tcx.span, message, ) diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6c72a7c31591e..bfc74979af42c 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -27,7 +27,7 @@ use syntax::ast::{self, Name}; use syntax::symbol::InternedString; use syntax_pos::{Span, DUMMY_SP}; use crate::ty::fold::{TypeFoldable, TypeFolder, TypeVisitor}; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::layout::VariantIdx; use crate::ty::{ self, AdtDef, CanonicalUserTypeAnnotations, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt, @@ -413,7 +413,7 @@ pub enum Safety { /// Unsafe because of an unsafe fn FnUnsafe, /// Unsafe because of an `unsafe` block - ExplicitUnsafe(ast::NodeId), + ExplicitUnsafe(hir::HirId), } impl_stable_hash_for!(struct Mir<'tcx> { @@ -2103,8 +2103,8 @@ pub struct SourceScopeData { #[derive(Clone, Debug, RustcEncodable, RustcDecodable)] pub struct SourceScopeLocalData { - /// A NodeId with lint levels equivalent to this scope's lint levels. - pub lint_root: ast::NodeId, + /// A HirId with lint levels equivalent to this scope's lint levels. + pub lint_root: hir::HirId, /// The unsafe block that contains this node. pub safety: Safety, } @@ -2151,7 +2151,7 @@ impl<'tcx> Operand<'tcx> { pub fn function_handle<'a>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, span: Span, ) -> Self { let ty = tcx.type_of(def_id).subst(tcx, substs); @@ -2247,7 +2247,7 @@ pub enum AggregateKind<'tcx> { Adt( &'tcx AdtDef, VariantIdx, - &'tcx Substs<'tcx>, + SubstsRef<'tcx>, Option, Option, ), @@ -2854,8 +2854,8 @@ pub enum UnsafetyViolationKind { General, /// Permitted in const fn and regular fns. GeneralAndConstFn, - ExternStatic(ast::NodeId), - BorrowPacked(ast::NodeId), + ExternStatic(hir::HirId), + BorrowPacked(hir::HirId), } #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] @@ -2872,7 +2872,7 @@ pub struct UnsafetyCheckResult { pub violations: Lrc<[UnsafetyViolation]>, /// unsafe blocks in this function, along with whether they are used. This is /// used for the "unused_unsafe" lint. - pub unsafe_blocks: Lrc<[(ast::NodeId, bool)]>, + pub unsafe_blocks: Lrc<[(hir::HirId, bool)]>, } /// The layout of generator state diff --git a/src/librustc/mir/tcx.rs b/src/librustc/mir/tcx.rs index bf4ac7496d2e7..dbf911851bf2d 100644 --- a/src/librustc/mir/tcx.rs +++ b/src/librustc/mir/tcx.rs @@ -4,7 +4,7 @@ */ use crate::mir::*; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, AdtDef, Ty, TyCtxt}; use crate::ty::layout::VariantIdx; use crate::hir; @@ -17,7 +17,7 @@ pub enum PlaceTy<'tcx> { /// Downcast to a particular variant of an enum. Downcast { adt_def: &'tcx AdtDef, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, variant_index: VariantIdx }, } diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index e5828039ac29c..4f31cebca088d 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -1,5 +1,5 @@ use crate::hir::def_id::DefId; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty}; use crate::mir::*; use syntax_pos::Span; @@ -238,7 +238,7 @@ macro_rules! make_mir_visitor { } fn visit_substs(&mut self, - substs: & $($mutability)? &'tcx Substs<'tcx>, + substs: & $($mutability)? SubstsRef<'tcx>, _: Location) { self.super_substs(substs); } @@ -889,7 +889,7 @@ macro_rules! make_mir_visitor { fn super_const(&mut self, _const: & $($mutability)? &'tcx ty::LazyConst<'tcx>) { } - fn super_substs(&mut self, _substs: & $($mutability)? &'tcx Substs<'tcx>) { + fn super_substs(&mut self, _substs: & $($mutability)? SubstsRef<'tcx>) { } fn super_generator_substs(&mut self, diff --git a/src/librustc/traits/auto_trait.rs b/src/librustc/traits/auto_trait.rs index 60a3777abf844..e93351197fe47 100644 --- a/src/librustc/traits/auto_trait.rs +++ b/src/librustc/traits/auto_trait.rs @@ -631,7 +631,7 @@ impl<'a, 'tcx> AutoTraitFinder<'a, 'tcx> { finished_map } - fn is_param_no_infer(&self, substs: &Substs<'_>) -> bool { + fn is_param_no_infer(&self, substs: SubstsRef<'_>) -> bool { return self.is_of_param(substs.type_at(0)) && !substs.types().any(|t| t.has_infer_types()); } diff --git a/src/librustc/traits/codegen/mod.rs b/src/librustc/traits/codegen/mod.rs index d6b7b3b99cacd..9b0a3820c859c 100644 --- a/src/librustc/traits/codegen/mod.rs +++ b/src/librustc/traits/codegen/mod.rs @@ -11,7 +11,7 @@ use syntax_pos::Span; use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, TraitEngine, Vtable}; use crate::ty::{self, Ty, TyCtxt}; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::fold::TypeFoldable; /// Attempts to resolve an obligation to a vtable. The result is @@ -82,7 +82,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { /// types. pub fn subst_and_normalize_erasing_regions( self, - param_substs: &Substs<'tcx>, + param_substs: SubstsRef<'tcx>, param_env: ty::ParamEnv<'tcx>, value: &T ) -> T diff --git a/src/librustc/traits/mod.rs b/src/librustc/traits/mod.rs index 99d1e32d52398..ee7893a27de7d 100644 --- a/src/librustc/traits/mod.rs +++ b/src/librustc/traits/mod.rs @@ -29,7 +29,7 @@ use crate::mir::interpret::ErrorHandled; use rustc_data_structures::sync::Lrc; use syntax::ast; use syntax_pos::{Span, DUMMY_SP}; -use crate::ty::subst::Substs; +use crate::ty::subst::{InternalSubsts, SubstsRef}; use crate::ty::{self, AdtKind, List, Ty, TyCtxt, GenericParamDefKind, ToPredicate}; use crate::ty::error::{ExpectedFound, TypeError}; use crate::ty::fold::{TypeFolder, TypeFoldable, TypeVisitor}; @@ -257,10 +257,10 @@ pub enum ObligationCauseCode<'tcx> { ReturnNoExpression, /// `return` with an expression - ReturnType(ast::NodeId), + ReturnType(hir::HirId), /// Block implicit return - BlockTailExpression(ast::NodeId), + BlockTailExpression(hir::HirId), /// #[feature(trivial_bounds)] is not enabled TrivialBound, @@ -565,7 +565,7 @@ pub enum Vtable<'tcx, N> { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableImplData<'tcx, N> { pub impl_def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, pub nested: Vec } @@ -622,7 +622,7 @@ pub struct VtableFnPointerData<'tcx, N> { #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable)] pub struct VtableTraitAliasData<'tcx, N> { pub alias_def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, pub nested: Vec, } @@ -963,7 +963,7 @@ fn normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - key: (DefId, &'tcx Substs<'tcx>)) + key: (DefId, SubstsRef<'tcx>)) -> bool { debug!("substitute_normalize_and_test_predicates(key={:?})", @@ -983,7 +983,7 @@ fn substitute_normalize_and_test_predicates<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx fn vtable_methods<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) - -> Lrc)>>> + -> Lrc)>>> { debug!("vtable_methods({:?})", trait_ref); @@ -992,7 +992,7 @@ fn vtable_methods<'a, 'tcx>( let trait_methods = tcx.associated_items(trait_ref.def_id()) .filter(|item| item.kind == ty::AssociatedKind::Method); - // Now list each method's DefId and Substs (for within its trait). + // Now list each method's DefId and InternalSubsts (for within its trait). // If the method can never be called from this object, produce None. trait_methods.map(move |trait_method| { debug!("vtable_methods: trait_method={:?}", trait_method); @@ -1007,7 +1007,7 @@ fn vtable_methods<'a, 'tcx>( // the method may have some early-bound lifetimes, add // regions for those let substs = trait_ref.map_bound(|trait_ref| - Substs::for_item(tcx, def_id, |param, _| + InternalSubsts::for_item(tcx, def_id, |param, _| match param.kind { GenericParamDefKind::Lifetime => tcx.types.re_erased.into(), GenericParamDefKind::Type {..} => { diff --git a/src/librustc/traits/object_safety.rs b/src/librustc/traits/object_safety.rs index b31aa5998f365..b2079c2516935 100644 --- a/src/librustc/traits/object_safety.rs +++ b/src/librustc/traits/object_safety.rs @@ -10,11 +10,12 @@ use super::elaborate_predicates; +use crate::hir; use crate::hir::def_id::DefId; use crate::lint; use crate::traits::{self, Obligation, ObligationCause}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable, Predicate, ToPredicate}; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts}; use std::borrow::Cow; use std::iter::{self}; use syntax::ast::{self, Name}; @@ -129,7 +130,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { // It's also hard to get a use site span, so we use the method definition span. self.lint_node_note( lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, *span, &format!("the trait `{}` cannot be made into an object", self.item_path_str(trait_def_id)), @@ -405,7 +406,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { self, receiver_ty: Ty<'tcx>, self_ty: Ty<'tcx>, method_def_id: DefId ) -> Ty<'tcx> { debug!("receiver_for_self_ty({:?}, {:?}, {:?})", receiver_ty, self_ty, method_def_id); - let substs = Substs::for_item(self, method_def_id, |param, _| { + let substs = InternalSubsts::for_item(self, method_def_id, |param, _| { if param.index == 0 { self_ty.into() } else { @@ -558,13 +559,17 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { // U: Trait let trait_predicate = { - let substs = Substs::for_item(self, method.container.assert_trait(), |param, _| { - if param.index == 0 { - unsized_self_ty.into() - } else { - self.mk_param_from_def(param) - } - }); + let substs = InternalSubsts::for_item( + self, + method.container.assert_trait(), + |param, _| { + if param.index == 0 { + unsized_self_ty.into() + } else { + self.mk_param_from_def(param) + } + }, + ); ty::TraitRef { def_id: unsize_did, diff --git a/src/librustc/traits/project.rs b/src/librustc/traits/project.rs index 05141c9daf1d4..72df12bc535a6 100644 --- a/src/librustc/traits/project.rs +++ b/src/librustc/traits/project.rs @@ -18,7 +18,7 @@ use crate::infer::type_variable::TypeVariableOrigin; use crate::mir::interpret::{GlobalId}; use rustc_data_structures::snapshot_map::{Snapshot, SnapshotMap}; use syntax::ast::Ident; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts}; use crate::ty::{self, ToPredicate, ToPolyTraitRef, Ty, TyCtxt}; use crate::ty::fold::{TypeFoldable, TypeFolder}; use crate::util::common::FN_OUTPUT_NAME; @@ -401,7 +401,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for AssociatedTypeNormalizer<'a, let tcx = self.selcx.tcx().global_tcx(); if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) { if substs.needs_infer() || substs.has_placeholders() { - let identity_substs = Substs::identity_for_item(tcx, def_id); + let identity_substs = InternalSubsts::identity_for_item(tcx, def_id); let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs); if let Some(instance) = instance { let cid = GlobalId { @@ -1490,7 +1490,7 @@ fn confirm_impl_candidate<'cx, 'gcx, 'tcx>( } let substs = translate_substs(selcx.infcx(), param_env, impl_def_id, substs, assoc_ty.node); let ty = if let ty::AssociatedKind::Existential = assoc_ty.item.kind { - let item_substs = Substs::identity_for_item(tcx, assoc_ty.item.def_id); + let item_substs = InternalSubsts::identity_for_item(tcx, assoc_ty.item.def_id); tcx.mk_opaque(assoc_ty.item.def_id, item_substs) } else { tcx.type_of(assoc_ty.item.def_id) diff --git a/src/librustc/traits/query/normalize.rs b/src/librustc/traits/query/normalize.rs index 224076ce17e72..8a30c18d6e5f7 100644 --- a/src/librustc/traits/query/normalize.rs +++ b/src/librustc/traits/query/normalize.rs @@ -9,7 +9,7 @@ use crate::mir::interpret::GlobalId; use crate::traits::project::Normalized; use crate::traits::{Obligation, ObligationCause, PredicateObligation, Reveal}; use crate::ty::fold::{TypeFoldable, TypeFolder}; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts}; use crate::ty::{self, Ty, TyCtxt}; use super::NoSolution; @@ -193,7 +193,7 @@ impl<'cx, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for QueryNormalizer<'cx, 'gcx, 'tcx let tcx = self.infcx.tcx.global_tcx(); if let Some(param_env) = self.tcx().lift_to_global(&self.param_env) { if substs.needs_infer() || substs.has_placeholders() { - let identity_substs = Substs::identity_for_item(tcx, def_id); + let identity_substs = InternalSubsts::identity_for_item(tcx, def_id); let instance = ty::Instance::resolve(tcx, param_env, def_id, identity_substs); if let Some(instance) = instance { let cid = GlobalId { diff --git a/src/librustc/traits/select.rs b/src/librustc/traits/select.rs index 05fb40ac10a07..e7cc9618080c2 100644 --- a/src/librustc/traits/select.rs +++ b/src/librustc/traits/select.rs @@ -34,7 +34,7 @@ use crate::middle::lang_items; use crate::mir::interpret::GlobalId; use crate::ty::fast_reject; use crate::ty::relate::TypeRelation; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, SubstsRef}; use crate::ty::{self, ToPolyTraitRef, ToPredicate, Ty, TyCtxt, TypeFoldable}; use crate::hir; @@ -1944,7 +1944,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { if let ty::FnSig { unsafety: hir::Unsafety::Normal, abi: Abi::Rust, - variadic: false, + c_variadic: false, .. } = self_ty.fn_sig(self.tcx()).skip_binder() { @@ -2944,7 +2944,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { fn vtable_impl( &mut self, impl_def_id: DefId, - mut substs: Normalized<'tcx, &'tcx Substs<'tcx>>, + mut substs: Normalized<'tcx, SubstsRef<'tcx>>, cause: ObligationCause<'tcx>, recursion_depth: usize, param_env: ty::ParamEnv<'tcx>, @@ -3538,7 +3538,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { impl_def_id: DefId, obligation: &TraitObligation<'tcx>, snapshot: &CombinedSnapshot<'_, 'tcx>, - ) -> Normalized<'tcx, &'tcx Substs<'tcx>> { + ) -> Normalized<'tcx, SubstsRef<'tcx>> { match self.match_impl(impl_def_id, obligation, snapshot) { Ok(substs) => substs, Err(()) => { @@ -3556,7 +3556,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { impl_def_id: DefId, obligation: &TraitObligation<'tcx>, snapshot: &CombinedSnapshot<'_, 'tcx>, - ) -> Result>, ()> { + ) -> Result>, ()> { let impl_trait_ref = self.tcx().impl_trait_ref(impl_def_id).unwrap(); // Before we create the substitutions and everything, first @@ -3761,7 +3761,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> { recursion_depth: usize, param_env: ty::ParamEnv<'tcx>, def_id: DefId, // of impl or trait - substs: &Substs<'tcx>, // for impl or trait + substs: SubstsRef<'tcx>, // for impl or trait ) -> Vec> { debug!("impl_or_trait_obligations(def_id={:?})", def_id); let tcx = self.tcx(); diff --git a/src/librustc/traits/specialize/mod.rs b/src/librustc/traits/specialize/mod.rs index 804f1b9d820a2..1d84f22acd9f8 100644 --- a/src/librustc/traits/specialize/mod.rs +++ b/src/librustc/traits/specialize/mod.rs @@ -20,7 +20,7 @@ use rustc_data_structures::sync::Lrc; use syntax_pos::DUMMY_SP; use crate::traits::select::IntercrateAmbiguityCause; use crate::ty::{self, TyCtxt, TypeFoldable}; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts, SubstsRef}; use super::{SelectionContext, FulfillmentContext}; use super::util::impl_trait_ref_and_oblig; @@ -73,9 +73,9 @@ pub struct OverlapError { pub fn translate_substs<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, source_impl: DefId, - source_substs: &'tcx Substs<'tcx>, + source_substs: SubstsRef<'tcx>, target_node: specialization_graph::Node) - -> &'tcx Substs<'tcx> { + -> SubstsRef<'tcx> { debug!("translate_substs({:?}, {:?}, {:?}, {:?})", param_env, source_impl, source_substs, target_node); let source_trait_ref = infcx.tcx @@ -114,9 +114,9 @@ pub fn find_associated_item<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, item: &ty::AssociatedItem, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, impl_data: &super::VtableImplData<'tcx, ()>, -) -> (DefId, &'tcx Substs<'tcx>) { +) -> (DefId, SubstsRef<'tcx>) { debug!("find_associated_item({:?}, {:?}, {:?}, {:?})", param_env, item, substs, impl_data); assert!(!substs.needs_infer()); @@ -214,7 +214,7 @@ fn fulfill_implication<'a, 'gcx, 'tcx>(infcx: &InferCtxt<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, source_trait_ref: ty::TraitRef<'tcx>, target_impl: DefId) - -> Result<&'tcx Substs<'tcx>, ()> { + -> Result, ()> { debug!("fulfill_implication({:?}, trait_ref={:?} |- {:?} applies)", param_env, source_trait_ref, target_impl); @@ -399,7 +399,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_, '_, '_>, impl_def_id: DefId) -> Option< let mut w = "impl".to_owned(); - let substs = Substs::identity_for_item(tcx, impl_def_id); + let substs = InternalSubsts::identity_for_item(tcx, impl_def_id); // FIXME: Currently only handles ?Sized. // Needs to support ?Move and ?DynSized when they are implemented. diff --git a/src/librustc/traits/util.rs b/src/librustc/traits/util.rs index 754cc94073b10..c3223f0cd6331 100644 --- a/src/librustc/traits/util.rs +++ b/src/librustc/traits/util.rs @@ -3,7 +3,7 @@ use crate::hir::def_id::DefId; use crate::traits::specialize::specialization_graph::NodeItem; use crate::ty::{self, Ty, TyCtxt, ToPredicate, ToPolyTraitRef}; use crate::ty::outlives::Component; -use crate::ty::subst::{Kind, Subst, Substs}; +use crate::ty::subst::{Kind, Subst, SubstsRef}; use crate::util::nodemap::FxHashSet; use super::{Obligation, ObligationCause, PredicateObligation, SelectionContext, Normalized}; @@ -358,7 +358,7 @@ impl<'tcx, I: Iterator>> Iterator for FilterToTraits< pub fn impl_trait_ref_and_oblig<'a, 'gcx, 'tcx>(selcx: &mut SelectionContext<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, impl_def_id: DefId, - impl_substs: &Substs<'tcx>) + impl_substs: SubstsRef<'tcx>,) -> (ty::TraitRef<'tcx>, Vec>) { diff --git a/src/librustc/ty/adjustment.rs b/src/librustc/ty/adjustment.rs index ff4fc87542dc3..8d449f5c44cf4 100644 --- a/src/librustc/ty/adjustment.rs +++ b/src/librustc/ty/adjustment.rs @@ -1,7 +1,7 @@ use crate::hir; use crate::hir::def_id::DefId; use crate::ty::{self, Ty, TyCtxt}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; /// Represents coercing a value to a different type of value. @@ -98,7 +98,7 @@ pub struct OverloadedDeref<'tcx> { impl<'a, 'gcx, 'tcx> OverloadedDeref<'tcx> { pub fn method_call(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, source: Ty<'tcx>) - -> (DefId, &'tcx Substs<'tcx>) { + -> (DefId, SubstsRef<'tcx>) { let trait_def_id = match self.mutbl { hir::MutImmutable => tcx.lang_items().deref_trait(), hir::MutMutable => tcx.lang_items().deref_mut_trait() diff --git a/src/librustc/ty/codec.rs b/src/librustc/ty/codec.rs index e93de32f7257b..3ab744ebaeb17 100644 --- a/src/librustc/ty/codec.rs +++ b/src/librustc/ty/codec.rs @@ -13,7 +13,7 @@ use crate::rustc_serialize::{Decodable, Decoder, Encoder, Encodable, opaque}; use std::hash::Hash; use std::intrinsics; use crate::ty::{self, Ty, TyCtxt}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::mir::interpret::Allocation; /// The shorthand encoding uses an enum's variant index `usize` @@ -185,7 +185,7 @@ pub fn decode_predicates<'a, 'tcx, D>(decoder: &mut D) } #[inline] -pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result<&'tcx Substs<'tcx>, D::Error> +pub fn decode_substs<'a, 'tcx, D>(decoder: &mut D) -> Result, D::Error> where D: TyDecoder<'a, 'tcx>, 'tcx: 'a, { @@ -281,7 +281,7 @@ macro_rules! implement_ty_decoder { use $crate::infer::canonical::CanonicalVarInfos; use $crate::ty; use $crate::ty::codec::*; - use $crate::ty::subst::Substs; + use $crate::ty::subst::SubstsRef; use $crate::hir::def_id::{CrateNum}; use crate::rustc_serialize::{Decoder, SpecializedDecoder}; use std::borrow::Cow; @@ -344,9 +344,9 @@ macro_rules! implement_ty_decoder { } } - impl<$($typaram),*> SpecializedDecoder<&'tcx Substs<'tcx>> + impl<$($typaram),*> SpecializedDecoder> for $DecoderName<$($typaram),*> { - fn specialized_decode(&mut self) -> Result<&'tcx Substs<'tcx>, Self::Error> { + fn specialized_decode(&mut self) -> Result, Self::Error> { decode_substs(self) } } diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index 6bb3222512565..9767396147cf9 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -22,7 +22,7 @@ use crate::middle::resolve_lifetime::{self, ObjectLifetimeDefault}; use crate::middle::stability; use crate::mir::{self, Mir, interpret, ProjectionKind}; use crate::mir::interpret::Allocation; -use crate::ty::subst::{Kind, Substs, Subst}; +use crate::ty::subst::{Kind, InternalSubsts, Subst, SubstsRef}; use crate::ty::ReprOptions; use crate::traits; use crate::traits::{Clause, Clauses, GoalKind, Goal, Goals}; @@ -118,7 +118,7 @@ pub struct CtxtInterners<'tcx> { /// they're accessed quite often. type_: InternedSet<'tcx, TyS<'tcx>>, type_list: InternedSet<'tcx, List>>, - substs: InternedSet<'tcx, Substs<'tcx>>, + substs: InternedSet<'tcx, InternalSubsts<'tcx>>, canonical_var_infos: InternedSet<'tcx, List>, region: InternedSet<'tcx, RegionKind>, existential_predicates: InternedSet<'tcx, List>>, @@ -325,7 +325,7 @@ pub struct ResolvedOpaqueTy<'tcx> { /// Generic parameters on the opaque type as passed by this function. /// For `existential type Foo; fn foo() -> Foo { .. }` this is `[T, U]`, not /// `[A, B]` - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } #[derive(RustcEncodable, RustcDecodable, Debug)] @@ -352,7 +352,7 @@ pub struct TypeckTables<'tcx> { /// of this node. This only applies to nodes that refer to entities /// parameterized by type parameters, such as generic fns, types, or /// other items. - node_substs: ItemLocalMap<&'tcx Substs<'tcx>>, + node_substs: ItemLocalMap>, /// This will either store the canonicalized types provided by the user /// or the substitutions that the user explicitly gave (if any) attached @@ -548,19 +548,19 @@ impl<'tcx> TypeckTables<'tcx> { self.node_types.get(&id.local_id).cloned() } - pub fn node_substs_mut(&mut self) -> LocalTableInContextMut<'_, &'tcx Substs<'tcx>> { + pub fn node_substs_mut(&mut self) -> LocalTableInContextMut<'_, SubstsRef<'tcx>> { LocalTableInContextMut { local_id_root: self.local_id_root, data: &mut self.node_substs } } - pub fn node_substs(&self, id: hir::HirId) -> &'tcx Substs<'tcx> { + pub fn node_substs(&self, id: hir::HirId) -> SubstsRef<'tcx> { validate_hir_id_for_typeck_tables(self.local_id_root, id, false); - self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| Substs::empty()) + self.node_substs.get(&id.local_id).cloned().unwrap_or_else(|| InternalSubsts::empty()) } - pub fn node_substs_opt(&self, id: hir::HirId) -> Option<&'tcx Substs<'tcx>> { + pub fn node_substs_opt(&self, id: hir::HirId) -> Option> { validate_hir_id_for_typeck_tables(self.local_id_root, id, false); self.node_substs.get(&id.local_id).cloned() } @@ -1733,7 +1733,7 @@ impl<'gcx> GlobalCtxt<'gcx> { /// A trait implemented for all X<'a> types which can be safely and /// efficiently converted to X<'tcx> as long as they are part of the /// provided TyCtxt<'tcx>. -/// This can be done, for example, for Ty<'tcx> or &'tcx Substs<'tcx> +/// This can be done, for example, for Ty<'tcx> or SubstsRef<'tcx> /// by looking them up in their respective interners. /// /// However, this is still not the best implementation as it does @@ -1807,7 +1807,7 @@ nop_list_lift!{Predicate<'a> => Predicate<'tcx>} nop_list_lift!{CanonicalVarInfo => CanonicalVarInfo} nop_list_lift!{ProjectionKind<'a> => ProjectionKind<'tcx>} -// this is the impl for `&'a Substs<'a>` +// this is the impl for `&'a InternalSubsts<'a>` nop_list_lift!{Kind<'a> => Kind<'tcx>} impl<'a, 'tcx> Lift<'tcx> for &'a mir::interpret::Allocation { @@ -2183,7 +2183,7 @@ impl<'a, 'tcx> TyCtxt<'a, 'tcx, 'tcx> { Generator, GeneratorWitness, Dynamic, Closure, Tuple, Bound, Param, Infer, UnnormalizedProjection, Projection, Opaque, Foreign); - println!("Substs interner: #{}", self.interners.substs.borrow().len()); + println!("InternalSubsts interner: #{}", self.interners.substs.borrow().len()); println!("Region interner: #{}", self.interners.region.borrow().len()); println!("Stability interner: #{}", self.stability_interner.borrow().len()); println!("Allocation interner: #{}", self.allocation_interner.borrow().len()); @@ -2250,7 +2250,7 @@ impl<'tcx: 'lcx, 'lcx> Borrow<[CanonicalVarInfo]> for Interned<'tcx, List Borrow<[Kind<'lcx>]> for Interned<'tcx, Substs<'tcx>> { +impl<'tcx: 'lcx, 'lcx> Borrow<[Kind<'lcx>]> for Interned<'tcx, InternalSubsts<'tcx>> { fn borrow<'a>(&'a self) -> &'a [Kind<'lcx>] { &self.0[..] } @@ -2453,7 +2453,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { self.mk_fn_sig( params_iter, s.output(), - s.variadic, + s.c_variadic, hir::Unsafety::Normal, abi::Abi::Rust, ) @@ -2507,7 +2507,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } #[inline] - pub fn mk_adt(self, def: &'tcx AdtDef, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> { + pub fn mk_adt(self, def: &'tcx AdtDef, substs: SubstsRef<'tcx>) -> Ty<'tcx> { // take a copy of substs so that we own the vectors inside self.mk_ty(Adt(def, substs)) } @@ -2520,7 +2520,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_box(self, ty: Ty<'tcx>) -> Ty<'tcx> { let def_id = self.require_lang_item(lang_items::OwnedBoxLangItem); let adt_def = self.adt_def(def_id); - let substs = Substs::for_item(self, def_id, |param, substs| { + let substs = InternalSubsts::for_item(self, def_id, |param, substs| { match param.kind { GenericParamDefKind::Lifetime => bug!(), GenericParamDefKind::Type { has_default, .. } => { @@ -2613,7 +2613,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { #[inline] pub fn mk_fn_def(self, def_id: DefId, - substs: &'tcx Substs<'tcx>) -> Ty<'tcx> { + substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty(FnDef(def_id, substs)) } @@ -2634,7 +2634,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { #[inline] pub fn mk_projection(self, item_def_id: DefId, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty(Projection(ProjectionTy { item_def_id, @@ -2704,7 +2704,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } #[inline] - pub fn mk_opaque(self, def_id: DefId, substs: &'tcx Substs<'tcx>) -> Ty<'tcx> { + pub fn mk_opaque(self, def_id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.mk_ty(Opaque(def_id, substs)) } @@ -2779,7 +2779,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_fn_sig(self, inputs: I, output: I::Item, - variadic: bool, + c_variadic: bool, unsafety: hir::Unsafety, abi: abi::Abi) -> , ty::FnSig<'tcx>>>::Output @@ -2788,7 +2788,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { { inputs.chain(iter::once(output)).intern_with(|xs| ty::FnSig { inputs_and_output: self.intern_type_list(xs), - variadic, unsafety, abi + c_variadic, unsafety, abi }) } @@ -2817,7 +2817,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn mk_substs_trait(self, self_ty: Ty<'tcx>, rest: &[Kind<'tcx>]) - -> &'tcx Substs<'tcx> + -> SubstsRef<'tcx> { self.mk_substs(iter::once(self_ty.into()).chain(rest.iter().cloned())) } @@ -2859,11 +2859,11 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn lint_node_note>(self, lint: &'static Lint, - id: NodeId, + id: hir::HirId, span: S, msg: &str, note: &str) { - let mut err = self.struct_span_lint_node(lint, id, span.into(), msg); + let mut err = self.struct_span_lint_hir(lint, id, span.into(), msg); err.note(note); err.emit() } diff --git a/src/librustc/ty/flags.rs b/src/librustc/ty/flags.rs index 25ec3e49cdf67..2b12dcca93ad7 100644 --- a/src/librustc/ty/flags.rs +++ b/src/librustc/ty/flags.rs @@ -1,4 +1,4 @@ -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::ty::{self, Ty, TypeFlags, TypeFoldable}; #[derive(Debug)] @@ -241,7 +241,7 @@ impl FlagComputation { self.add_substs(projection_ty.substs); } - fn add_substs(&mut self, substs: &Substs<'_>) { + fn add_substs(&mut self, substs: SubstsRef<'_>) { for ty in substs.types() { self.add_ty(ty); } diff --git a/src/librustc/ty/inhabitedness/mod.rs b/src/librustc/ty/inhabitedness/mod.rs index 601ffe70eec18..33ec9c874f9ef 100644 --- a/src/librustc/ty/inhabitedness/mod.rs +++ b/src/librustc/ty/inhabitedness/mod.rs @@ -1,6 +1,6 @@ use crate::ty::context::TyCtxt; use crate::ty::{AdtDef, VariantDef, FieldDef, Ty, TyS}; -use crate::ty::{self, DefId, Substs}; +use crate::ty::{self, DefId, SubstsRef}; use crate::ty::{AdtKind, Visibility}; use crate::ty::TyKind::*; @@ -108,7 +108,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn is_enum_variant_uninhabited_from(self, module: DefId, variant: &'tcx VariantDef, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> bool { self.variant_inhabitedness_forest(variant, substs).contains(self, module) @@ -116,13 +116,13 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn is_variant_uninhabited_from_all_modules(self, variant: &'tcx VariantDef, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> bool { !self.variant_inhabitedness_forest(variant, substs).is_empty() } - fn variant_inhabitedness_forest(self, variant: &'tcx VariantDef, substs: &'tcx Substs<'tcx>) + fn variant_inhabitedness_forest(self, variant: &'tcx VariantDef, substs: SubstsRef<'tcx>) -> DefIdForest { // Determine the ADT kind: let adt_def_id = self.adt_def_id_of_variant(variant); @@ -138,7 +138,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { fn uninhabited_from( &self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &'tcx Substs<'tcx>) -> DefIdForest + substs: SubstsRef<'tcx>) -> DefIdForest { DefIdForest::intersection(tcx, self.variants.iter().map(|v| { v.uninhabited_from(tcx, substs, self.adt_kind()) @@ -151,7 +151,7 @@ impl<'a, 'gcx, 'tcx> VariantDef { fn uninhabited_from( &self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, adt_kind: AdtKind) -> DefIdForest { let is_enum = match adt_kind { @@ -172,7 +172,7 @@ impl<'a, 'gcx, 'tcx> FieldDef { fn uninhabited_from( &self, tcx: TyCtxt<'a, 'gcx, 'tcx>, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, is_enum: bool, ) -> DefIdForest { let data_uninhabitedness = move || { diff --git a/src/librustc/ty/instance.rs b/src/librustc/ty/instance.rs index 5fc22e3c02b60..49ebd202813f6 100644 --- a/src/librustc/ty/instance.rs +++ b/src/librustc/ty/instance.rs @@ -1,6 +1,6 @@ use crate::hir::Unsafety; use crate::hir::def_id::DefId; -use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, Substs, TyCtxt}; +use crate::ty::{self, Ty, PolyFnSig, TypeFoldable, SubstsRef, TyCtxt}; use crate::traits; use rustc_target::spec::abi::Abi; use crate::util::ppaux; @@ -11,7 +11,7 @@ use std::iter; #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] pub struct Instance<'tcx> { pub def: InstanceDef<'tcx>, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } #[derive(Copy, Clone, PartialEq, Eq, Hash, Debug, RustcEncodable, RustcDecodable)] @@ -65,7 +65,7 @@ impl<'a, 'tcx> Instance<'tcx> { sig.map_bound(|sig| tcx.mk_fn_sig( iter::once(*env_ty.skip_binder()).chain(sig.inputs().iter().cloned()), sig.output(), - sig.variadic, + sig.c_variadic, sig.unsafety, sig.abi )) @@ -203,7 +203,7 @@ impl<'tcx> fmt::Display for Instance<'tcx> { } impl<'a, 'b, 'tcx> Instance<'tcx> { - pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>) + pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> Instance<'tcx> { assert!(!substs.has_escaping_bound_vars(), "substs of instance {:?} not normalized for codegen: {:?}", @@ -241,7 +241,7 @@ impl<'a, 'b, 'tcx> Instance<'tcx> { pub fn resolve(tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>) -> Option> { + substs: SubstsRef<'tcx>) -> Option> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env); @@ -293,7 +293,7 @@ impl<'a, 'b, 'tcx> Instance<'tcx> { pub fn resolve_for_vtable(tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>) -> Option> { + substs: SubstsRef<'tcx>) -> Option> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); let fn_sig = tcx.fn_sig(def_id); let is_vtable_shim = @@ -338,7 +338,7 @@ fn resolve_associated_item<'a, 'tcx>( trait_item: &ty::AssociatedItem, param_env: ty::ParamEnv<'tcx>, trait_id: DefId, - rcvr_substs: &'tcx Substs<'tcx>, + rcvr_substs: SubstsRef<'tcx>, ) -> Option> { let def_id = trait_item.def_id; debug!("resolve_associated_item(trait_item={:?}, \ diff --git a/src/librustc/ty/mod.rs b/src/librustc/ty/mod.rs index 02e4fb12af5c9..5243c4dbfd209 100644 --- a/src/librustc/ty/mod.rs +++ b/src/librustc/ty/mod.rs @@ -22,7 +22,7 @@ use crate::session::CrateDisambiguator; use crate::traits::{self, Reveal}; use crate::ty; use crate::ty::layout::VariantIdx; -use crate::ty::subst::{Subst, Substs}; +use crate::ty::subst::{Subst, InternalSubsts, SubstsRef}; use crate::ty::util::{IntTypeExt, Discr}; use crate::ty::walk::TypeWalker; use crate::util::captures::Captures; @@ -982,14 +982,14 @@ impl<'tcx> serialize::UseSpecializedEncodable for GenericPredicates<'tcx> {} impl<'tcx> serialize::UseSpecializedDecodable for GenericPredicates<'tcx> {} impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> { - pub fn instantiate(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>) + pub fn instantiate(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: SubstsRef<'tcx>) -> InstantiatedPredicates<'tcx> { let mut instantiated = InstantiatedPredicates::empty(); self.instantiate_into(tcx, &mut instantiated, substs); instantiated } - pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: &Substs<'tcx>) + pub fn instantiate_own(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, substs: SubstsRef<'tcx>) -> InstantiatedPredicates<'tcx> { InstantiatedPredicates { predicates: self.predicates.iter().map(|(p, _)| p.subst(tcx, substs)).collect(), @@ -998,7 +998,7 @@ impl<'a, 'gcx, 'tcx> GenericPredicates<'tcx> { fn instantiate_into(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, instantiated: &mut InstantiatedPredicates<'tcx>, - substs: &Substs<'tcx>) { + substs: SubstsRef<'tcx>) { if let Some(def_id) = self.parent { tcx.predicates_of(def_id).instantiate_into(tcx, instantiated, substs); } @@ -1067,7 +1067,7 @@ pub enum Predicate<'tcx> { Subtype(PolySubtypePredicate<'tcx>), /// Constant initializer must evaluate successfully. - ConstEvaluatable(DefId, &'tcx Substs<'tcx>), + ConstEvaluatable(DefId, SubstsRef<'tcx>), } /// The crate outlives map is computed during typeck and contains the @@ -2261,7 +2261,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { ) -> Option> { let param_env = ParamEnv::empty(); let repr_type = self.repr.discr_type(); - let substs = Substs::identity_for_item(tcx.global_tcx(), expr_did); + let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), expr_did); let instance = ty::Instance::new(expr_did, substs); let cid = GlobalId { instance, @@ -2463,7 +2463,7 @@ impl<'a, 'gcx, 'tcx> AdtDef { } impl<'a, 'gcx, 'tcx> FieldDef { - pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, subst: &Substs<'tcx>) -> Ty<'tcx> { + pub fn ty(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, subst: SubstsRef<'tcx>) -> Ty<'tcx> { tcx.type_of(self.did).subst(tcx, subst) } } @@ -2775,8 +2775,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { } } - pub fn field_index(self, node_id: NodeId, tables: &TypeckTables<'_>) -> usize { - let hir_id = self.hir().node_to_hir_id(node_id); + pub fn field_index(self, hir_id: hir::HirId, tables: &TypeckTables<'_>) -> usize { tables.field_indices().get(hir_id).cloned().expect("no index for a field") } diff --git a/src/librustc/ty/query/config.rs b/src/librustc/ty/query/config.rs index 1870812893c14..0d3e9f7914ba7 100644 --- a/src/librustc/ty/query/config.rs +++ b/src/librustc/ty/query/config.rs @@ -9,7 +9,7 @@ use crate::traits::query::{ CanonicalTypeOpProvePredicateGoal, CanonicalTypeOpSubtypeGoal, }; use crate::ty::{self, ParamEnvAnd, Ty, TyCtxt}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::ty::query::queries; use crate::ty::query::Query; use crate::ty::query::QueryCache; @@ -914,7 +914,7 @@ impl<'tcx> QueryDescription<'tcx> for queries::optimized_mir<'tcx> { } impl<'tcx> QueryDescription<'tcx> for queries::substitute_normalize_and_test_predicates<'tcx> { - fn describe(tcx: TyCtxt<'_, '_, '_>, key: (DefId, &'tcx Substs<'tcx>)) -> Cow<'static, str> { + fn describe(tcx: TyCtxt<'_, '_, '_>, key: (DefId, SubstsRef<'tcx>)) -> Cow<'static, str> { format!("testing substituted normalized predicates:`{}`", tcx.item_path_str(key.0)).into() } } diff --git a/src/librustc/ty/query/keys.rs b/src/librustc/ty/query/keys.rs index f5eb7374cc19b..d353da801778d 100644 --- a/src/librustc/ty/query/keys.rs +++ b/src/librustc/ty/query/keys.rs @@ -4,7 +4,7 @@ use crate::infer::canonical::Canonical; use crate::hir::def_id::{CrateNum, DefId, LOCAL_CRATE, DefIndex}; use crate::traits; use crate::ty::{self, Ty, TyCtxt}; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::ty::fast_reject::SimplifiedType; use crate::mir; @@ -109,7 +109,7 @@ impl Key for (DefId, SimplifiedType) { } } -impl<'tcx> Key for (DefId, &'tcx Substs<'tcx>) { +impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { fn query_crate(&self) -> CrateNum { self.0.krate } diff --git a/src/librustc/ty/query/mod.rs b/src/librustc/ty/query/mod.rs index 740875109d029..ee36a1af8f400 100644 --- a/src/librustc/ty/query/mod.rs +++ b/src/librustc/ty/query/mod.rs @@ -36,8 +36,8 @@ use crate::traits::specialization_graph; use crate::traits::Clauses; use crate::ty::{self, CrateInherentImpls, ParamEnvAnd, Ty, TyCtxt, AdtSizedConstraint}; use crate::ty::steal::Steal; -use crate::ty::subst::Substs; use crate::ty::util::NeedsDrop; +use crate::ty::subst::SubstsRef; use crate::util::nodemap::{DefIdSet, DefIdMap, ItemLocalSet}; use crate::util::common::{ErrorReported}; use crate::util::profiling::ProfileCategory::*; @@ -393,7 +393,7 @@ define_queries! { <'tcx> Other { [] fn vtable_methods: vtable_methods_node(ty::PolyTraitRef<'tcx>) - -> Lrc)>>>, + -> Lrc)>>>, }, Codegen { @@ -493,9 +493,9 @@ define_queries! { <'tcx> Codegen { [] fn upstream_monomorphizations: UpstreamMonomorphizations(CrateNum) - -> Lrc, CrateNum>>>>, + -> Lrc, CrateNum>>>>, [] fn upstream_monomorphizations_for: UpstreamMonomorphizationsFor(DefId) - -> Option, CrateNum>>>, + -> Option, CrateNum>>>, }, Other { @@ -714,7 +714,7 @@ define_queries! { <'tcx> >, [] fn substitute_normalize_and_test_predicates: - substitute_normalize_and_test_predicates_node((DefId, &'tcx Substs<'tcx>)) -> bool, + substitute_normalize_and_test_predicates_node((DefId, SubstsRef<'tcx>)) -> bool, [] fn method_autoderef_steps: MethodAutoderefSteps( CanonicalTyGoal<'tcx> @@ -906,7 +906,7 @@ fn vtable_methods_node<'tcx>(trait_ref: ty::PolyTraitRef<'tcx>) -> DepConstructo DepConstructor::VtableMethods{ trait_ref } } -fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, &'tcx Substs<'tcx>)) +fn substitute_normalize_and_test_predicates_node<'tcx>(key: (DefId, SubstsRef<'tcx>)) -> DepConstructor<'tcx> { DepConstructor::SubstituteNormalizeAndTestPredicates { key } } diff --git a/src/librustc/ty/relate.rs b/src/librustc/ty/relate.rs index db248072d9b50..2940757fa905b 100644 --- a/src/librustc/ty/relate.rs +++ b/src/librustc/ty/relate.rs @@ -5,7 +5,7 @@ //! subtyping, type equality, etc. use crate::hir::def_id::DefId; -use crate::ty::subst::{Kind, UnpackedKind, Substs}; +use crate::ty::subst::{Kind, UnpackedKind, SubstsRef}; use crate::ty::{self, Ty, TyCtxt, TypeFoldable}; use crate::ty::error::{ExpectedFound, TypeError}; use crate::mir::interpret::GlobalId; @@ -50,9 +50,9 @@ pub trait TypeRelation<'a, 'gcx: 'a+'tcx, 'tcx: 'a> : Sized { /// accordingly. fn relate_item_substs(&mut self, item_def_id: DefId, - a_subst: &'tcx Substs<'tcx>, - b_subst: &'tcx Substs<'tcx>) - -> RelateResult<'tcx, &'tcx Substs<'tcx>> + a_subst: SubstsRef<'tcx>, + b_subst: SubstsRef<'tcx>) + -> RelateResult<'tcx, SubstsRef<'tcx>> { debug!("relate_item_substs(item_def_id={:?}, a_subst={:?}, b_subst={:?})", item_def_id, @@ -123,9 +123,9 @@ impl<'tcx> Relate<'tcx> for ty::TypeAndMut<'tcx> { pub fn relate_substs<'a, 'gcx, 'tcx, R>(relation: &mut R, variances: Option<&Vec>, - a_subst: &'tcx Substs<'tcx>, - b_subst: &'tcx Substs<'tcx>) - -> RelateResult<'tcx, &'tcx Substs<'tcx>> + a_subst: SubstsRef<'tcx>, + b_subst: SubstsRef<'tcx>) + -> RelateResult<'tcx, SubstsRef<'tcx>> where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a { let tcx = relation.tcx(); @@ -147,9 +147,9 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { { let tcx = relation.tcx(); - if a.variadic != b.variadic { + if a.c_variadic != b.c_variadic { return Err(TypeError::VariadicMismatch( - expected_found(relation, &a.variadic, &b.variadic))); + expected_found(relation, &a.c_variadic, &b.c_variadic))); } let unsafety = relation.relate(&a.unsafety, &b.unsafety)?; let abi = relation.relate(&a.abi, &b.abi)?; @@ -171,7 +171,7 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { }); Ok(ty::FnSig { inputs_and_output: tcx.mk_type_list(inputs_and_output)?, - variadic: a.variadic, + c_variadic: a.c_variadic, unsafety, abi, }) @@ -624,11 +624,11 @@ impl<'tcx> Relate<'tcx> for ty::GeneratorSubsts<'tcx> { } } -impl<'tcx> Relate<'tcx> for &'tcx Substs<'tcx> { +impl<'tcx> Relate<'tcx> for SubstsRef<'tcx> { fn relate<'a, 'gcx, R>(relation: &mut R, - a: &&'tcx Substs<'tcx>, - b: &&'tcx Substs<'tcx>) - -> RelateResult<'tcx, &'tcx Substs<'tcx>> + a: &SubstsRef<'tcx>, + b: &SubstsRef<'tcx>) + -> RelateResult<'tcx, SubstsRef<'tcx>> where R: TypeRelation<'a, 'gcx, 'tcx>, 'gcx: 'a+'tcx, 'tcx: 'a { relate_substs(relation, None, a, b) diff --git a/src/librustc/ty/structural_impls.rs b/src/librustc/ty/structural_impls.rs index a81d5c9d86edd..f1a465e1f1724 100644 --- a/src/librustc/ty/structural_impls.rs +++ b/src/librustc/ty/structural_impls.rs @@ -396,7 +396,7 @@ impl<'a, 'tcx> Lift<'tcx> for ty::FnSig<'a> { tcx.lift(&self.inputs_and_output).map(|x| { ty::FnSig { inputs_and_output: x, - variadic: self.variadic, + c_variadic: self.c_variadic, unsafety: self.unsafety, abi: self.abi, } @@ -832,7 +832,7 @@ BraceStructTypeFoldableImpl! { BraceStructTypeFoldableImpl! { impl<'tcx> TypeFoldable<'tcx> for ty::FnSig<'tcx> { - inputs_and_output, variadic, unsafety, abi + inputs_and_output, c_variadic, unsafety, abi } } diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index dd382ec006bd7..3fd2e38a3d3e5 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -7,7 +7,7 @@ use crate::mir::interpret::{ConstValue, truncate}; use crate::middle::region; use polonius_engine::Atom; use rustc_data_structures::indexed_vec::Idx; -use crate::ty::subst::{Substs, Subst, Kind, UnpackedKind}; +use crate::ty::subst::{InternalSubsts, Subst, SubstsRef, Kind, UnpackedKind}; use crate::ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable}; use crate::ty::{List, TyS, ParamEnvAnd, ParamEnv}; use crate::util::captures::Captures; @@ -101,11 +101,11 @@ pub enum TyKind<'tcx> { /// Structures, enumerations and unions. /// - /// Substs here, possibly against intuition, *may* contain `Param`s. + /// InternalSubsts here, possibly against intuition, *may* contain `Param`s. /// That is, even after substitution it is possible that there are type /// variables. This happens when the `Adt` corresponds to an ADT /// definition and not a concrete use of it. - Adt(&'tcx AdtDef, &'tcx Substs<'tcx>), + Adt(&'tcx AdtDef, SubstsRef<'tcx>), /// An unsized FFI type that is opaque to Rust. Written as `extern type T`. Foreign(DefId), @@ -136,7 +136,7 @@ pub enum TyKind<'tcx> { /// fn foo() -> i32 { 1 } /// let bar = foo; // bar: fn() -> i32 {foo} /// ``` - FnDef(DefId, &'tcx Substs<'tcx>), + FnDef(DefId, SubstsRef<'tcx>), /// A pointer to a function. Written as `fn() -> i32`. /// @@ -184,7 +184,7 @@ pub enum TyKind<'tcx> { /// * or the `existential type` declaration /// The substitutions are for the generics of the function in question. /// After typeck, the concrete type can be found in the `types` map. - Opaque(DefId, &'tcx Substs<'tcx>), + Opaque(DefId, SubstsRef<'tcx>), /// A type parameter; for example, `T` in `fn f(x: T) {} Param(ParamTy), @@ -309,7 +309,7 @@ pub struct ClosureSubsts<'tcx> { /// /// These are separated out because codegen wants to pass them around /// when monomorphizing. - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } /// Struct returned by `split()`. Note that these are subslices of the @@ -387,7 +387,7 @@ impl<'tcx> ClosureSubsts<'tcx> { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] pub struct GeneratorSubsts<'tcx> { - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } struct SplitGeneratorSubsts<'tcx> { @@ -672,11 +672,11 @@ impl<'tcx> Binder<&'tcx List>> { #[derive(Copy, Clone, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub struct TraitRef<'tcx> { pub def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } impl<'tcx> TraitRef<'tcx> { - pub fn new(def_id: DefId, substs: &'tcx Substs<'tcx>) -> TraitRef<'tcx> { + pub fn new(def_id: DefId, substs: SubstsRef<'tcx>) -> TraitRef<'tcx> { TraitRef { def_id: def_id, substs: substs } } @@ -685,7 +685,7 @@ impl<'tcx> TraitRef<'tcx> { pub fn identity<'a, 'gcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) -> TraitRef<'tcx> { TraitRef { def_id, - substs: Substs::identity_for_item(tcx, def_id), + substs: InternalSubsts::identity_for_item(tcx, def_id), } } @@ -704,7 +704,7 @@ impl<'tcx> TraitRef<'tcx> { pub fn from_method(tcx: TyCtxt<'_, '_, 'tcx>, trait_id: DefId, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); @@ -742,7 +742,7 @@ impl<'tcx> PolyTraitRef<'tcx> { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] pub struct ExistentialTraitRef<'tcx> { pub def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, } impl<'a, 'gcx, 'tcx> ExistentialTraitRef<'tcx> { @@ -915,7 +915,7 @@ impl Binder { #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] pub struct ProjectionTy<'tcx> { /// The parameters of the associated item. - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, /// The `DefId` of the `TraitItem` for the associated type `N`. /// @@ -977,13 +977,13 @@ impl<'tcx> PolyGenSig<'tcx> { /// Signature of a function type, which I have arbitrarily /// decided to use to refer to the input/output types. /// -/// - `inputs` is the list of arguments and their modes. -/// - `output` is the return type. -/// - `variadic` indicates whether this is a variadic function. (only true for foreign fns) +/// - `inputs`: is the list of arguments and their modes. +/// - `output`: is the return type. +/// - `c_variadic`: indicates whether this is a C-variadic function. #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] pub struct FnSig<'tcx> { pub inputs_and_output: &'tcx List>, - pub variadic: bool, + pub c_variadic: bool, pub unsafety: hir::Unsafety, pub abi: abi::Abi, } @@ -1016,8 +1016,8 @@ impl<'tcx> PolyFnSig<'tcx> { pub fn output(&self) -> ty::Binder> { self.map_bound_ref(|fn_sig| fn_sig.output()) } - pub fn variadic(&self) -> bool { - self.skip_binder().variadic + pub fn c_variadic(&self) -> bool { + self.skip_binder().c_variadic } pub fn unsafety(&self) -> hir::Unsafety { self.skip_binder().unsafety @@ -1120,7 +1120,7 @@ pub type Region<'tcx> = &'tcx RegionKind; /// These are regions that are stored behind a binder and must be substituted /// with some concrete region before being used. There are two kind of /// bound regions: early-bound, which are bound in an item's `Generics`, -/// and are substituted by a `Substs`, and late-bound, which are part of +/// and are substituted by a `InternalSubsts`, and late-bound, which are part of /// higher-ranked types (e.g., `for<'a> fn(&'a ())`), and are substituted by /// the likes of `liberate_late_bound_regions`. The distinction exists /// because higher-ranked lifetimes aren't supported in all places. See [1][2]. @@ -1297,7 +1297,7 @@ impl From for BoundTy { #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, RustcEncodable, RustcDecodable)] pub struct ExistentialProjection<'tcx> { pub item_def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, pub ty: Ty<'tcx>, } @@ -2060,7 +2060,7 @@ impl<'a, 'gcx, 'tcx> TyS<'tcx> { /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to `Evaluated` if the /// code is monomorphic enough for that. pub enum LazyConst<'tcx> { - Unevaluated(DefId, &'tcx Substs<'tcx>), + Unevaluated(DefId, SubstsRef<'tcx>), Evaluated(Const<'tcx>), } diff --git a/src/librustc/ty/subst.rs b/src/librustc/ty/subst.rs index 7559ea90b1782..450fab81661fc 100644 --- a/src/librustc/ty/subst.rs +++ b/src/librustc/ty/subst.rs @@ -157,26 +157,28 @@ impl<'tcx> Decodable for Kind<'tcx> { } /// A substitution mapping generic parameters to new values. -pub type Substs<'tcx> = List>; +pub type InternalSubsts<'tcx> = List>; -impl<'a, 'gcx, 'tcx> Substs<'tcx> { - /// Creates a `Substs` that maps each generic parameter to itself. +pub type SubstsRef<'tcx> = &'tcx InternalSubsts<'tcx>; + +impl<'a, 'gcx, 'tcx> InternalSubsts<'tcx> { + /// Creates a `InternalSubsts` that maps each generic parameter to itself. pub fn identity_for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId) - -> &'tcx Substs<'tcx> { - Substs::for_item(tcx, def_id, |param, _| { + -> SubstsRef<'tcx> { + Self::for_item(tcx, def_id, |param, _| { tcx.mk_param_from_def(param) }) } - /// Creates a `Substs` that maps each generic parameter to a higher-ranked + /// Creates a `InternalSubsts` that maps each generic parameter to a higher-ranked /// var bound at index `0`. For types, we use a `BoundVar` index equal to /// the type parameter index. For regions, we use the `BoundRegion::BrNamed` /// variant (which has a `DefId`). pub fn bound_vars_for_item( tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId - ) -> &'tcx Substs<'tcx> { - Substs::for_item(tcx, def_id, |param, _| { + ) -> SubstsRef<'tcx> { + Self::for_item(tcx, def_id, |param, _| { match param.kind { ty::GenericParamDefKind::Type { .. } => { tcx.mk_ty( @@ -197,21 +199,21 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { }) } - /// Creates a `Substs` for generic parameter definitions, + /// Creates a `InternalSubsts` for generic parameter definitions, /// by calling closures to obtain each kind. - /// The closures get to observe the `Substs` as they're + /// The closures get to observe the `InternalSubsts` as they're /// being built, which can be used to correctly /// substitute defaults of generic parameters. pub fn for_item(tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId, mut mk_kind: F) - -> &'tcx Substs<'tcx> + -> SubstsRef<'tcx> where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> { let defs = tcx.generics_of(def_id); let count = defs.count(); let mut substs = SmallVec::with_capacity(count); - Substs::fill_item(&mut substs, tcx, defs, &mut mk_kind); + Self::fill_item(&mut substs, tcx, defs, &mut mk_kind); tcx.intern_substs(&substs) } @@ -219,10 +221,10 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId, mut mk_kind: F) - -> &'tcx Substs<'tcx> + -> SubstsRef<'tcx> where F: FnMut(&ty::GenericParamDef, &[Kind<'tcx>]) -> Kind<'tcx> { - Substs::for_item(tcx, def_id, |param, substs| { + Self::for_item(tcx, def_id, |param, substs| { self.get(param.index as usize) .cloned() .unwrap_or_else(|| mk_kind(param, substs)) @@ -237,9 +239,9 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { { if let Some(def_id) = defs.parent { let parent_defs = tcx.generics_of(def_id); - Substs::fill_item(substs, tcx, parent_defs, mk_kind); + Self::fill_item(substs, tcx, parent_defs, mk_kind); } - Substs::fill_single(substs, defs, mk_kind) + Self::fill_single(substs, defs, mk_kind) } fn fill_single(substs: &mut SmallVec<[Kind<'tcx>; 8]>, @@ -311,19 +313,19 @@ impl<'a, 'gcx, 'tcx> Substs<'tcx> { /// parameters (e.g., method parameters) on top of that base. pub fn rebase_onto(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, source_ancestor: DefId, - target_substs: &Substs<'tcx>) - -> &'tcx Substs<'tcx> { + target_substs: SubstsRef<'tcx>) + -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); tcx.mk_substs(target_substs.iter().chain(&self[defs.params.len()..]).cloned()) } pub fn truncate_to(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>, generics: &ty::Generics) - -> &'tcx Substs<'tcx> { + -> SubstsRef<'tcx> { tcx.mk_substs(self.iter().take(generics.count()).cloned()) } } -impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> { +impl<'tcx> TypeFoldable<'tcx> for SubstsRef<'tcx> { fn super_fold_with<'gcx: 'tcx, F: TypeFolder<'gcx, 'tcx>>(&self, folder: &mut F) -> Self { let params: SmallVec<[_; 8]> = self.iter().map(|k| k.fold_with(folder)).collect(); @@ -341,7 +343,7 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx Substs<'tcx> { } } -impl<'tcx> serialize::UseSpecializedDecodable for &'tcx Substs<'tcx> {} +impl<'tcx> serialize::UseSpecializedDecodable for SubstsRef<'tcx> {} /////////////////////////////////////////////////////////////////////////// // Public trait `Subst` @@ -563,7 +565,7 @@ pub type CanonicalUserSubsts<'tcx> = Canonical<'tcx, UserSubsts<'tcx>>; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, RustcEncodable, RustcDecodable)] pub struct UserSubsts<'tcx> { /// The substitutions for the item as given by the user. - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, /// The self type, in the case of a `::Item` path (when applied /// to an inherent impl). See `UserSelfTy` below. diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 1ba7c3bba797c..7374eba2e317b 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -7,7 +7,7 @@ use crate::hir::{self, Node}; use crate::ich::NodeIdHashingMode; use crate::traits::{self, ObligationCause}; use crate::ty::{self, Ty, TyCtxt, GenericParamDefKind, TypeFoldable}; -use crate::ty::subst::{Subst, Substs, UnpackedKind}; +use crate::ty::subst::{Subst, InternalSubsts, SubstsRef, UnpackedKind}; use crate::ty::query::TyCtxtAt; use crate::ty::TyKind::*; use crate::ty::layout::{Integer, IntegerExt}; @@ -588,8 +588,8 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { /// Given the `DefId` of some item that has no type parameters, make /// a suitable "empty substs" for it. - pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> &'tcx Substs<'tcx> { - Substs::for_item(self, item_def_id, |param, _| { + pub fn empty_substs_for_def_id(self, item_def_id: DefId) -> SubstsRef<'tcx> { + InternalSubsts::for_item(self, item_def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => self.types.re_erased.into(), GenericParamDefKind::Type {..} => { @@ -633,7 +633,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { pub fn try_expand_impl_trait_type( self, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> Result, Ty<'tcx>> { use crate::ty::fold::TypeFolder; @@ -652,7 +652,7 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> { fn expand_opaque_ty( &mut self, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> Option> { if self.found_recursion { None diff --git a/src/librustc/ty/walk.rs b/src/librustc/ty/walk.rs index 126f5290af513..d9f309ae58e03 100644 --- a/src/librustc/ty/walk.rs +++ b/src/librustc/ty/walk.rs @@ -99,7 +99,7 @@ fn push_subtypes<'tcx>(stack: &mut TypeWalkerStack<'tcx>, parent_ty: Ty<'tcx>) { (p.substs, Some(p.ty)), ty::ExistentialPredicate::AutoTrait(_) => // Empty iterator - (ty::Substs::empty(), None), + (ty::InternalSubsts::empty(), None), }; substs.types().rev().chain(opt_ty) diff --git a/src/librustc/ty/wf.rs b/src/librustc/ty/wf.rs index 282bf1219fa5c..599d38bc4ab6e 100644 --- a/src/librustc/ty/wf.rs +++ b/src/librustc/ty/wf.rs @@ -1,7 +1,7 @@ use crate::hir; use crate::hir::def_id::DefId; use crate::infer::InferCtxt; -use crate::ty::subst::Substs; +use crate::ty::subst::SubstsRef; use crate::traits; use crate::ty::{self, ToPredicate, Ty, TyCtxt, TypeFoldable}; use std::iter::once; @@ -432,7 +432,7 @@ impl<'a, 'gcx, 'tcx> WfPredicates<'a, 'gcx, 'tcx> { fn nominal_obligations(&mut self, def_id: DefId, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> Vec> { let predicates = diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 768fd02e8238a..aecef3c5ec71e 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -1,7 +1,7 @@ use crate::hir::def_id::DefId; use crate::hir::map::definitions::DefPathData; use crate::middle::region; -use crate::ty::subst::{self, Subst}; +use crate::ty::subst::{self, Subst, SubstsRef}; use crate::ty::{BrAnon, BrEnv, BrFresh, BrNamed}; use crate::ty::{Bool, Char, Adt}; use crate::ty::{Error, Str, Array, Slice, Float, FnDef, FnPtr}; @@ -360,7 +360,7 @@ impl PrintContext { fn fn_sig(&mut self, f: &mut F, inputs: &[Ty<'_>], - variadic: bool, + c_variadic: bool, output: Ty<'_>) -> fmt::Result { write!(f, "(")?; @@ -370,7 +370,7 @@ impl PrintContext { for &ty in inputs { print!(f, self, write(", "), print_display(ty))?; } - if variadic { + if c_variadic { write!(f, ", ...")?; } } @@ -384,7 +384,7 @@ impl PrintContext { fn parameterized(&mut self, f: &mut F, - substs: &subst::Substs<'_>, + substs: SubstsRef<'_>, did: DefId, projections: &[ty::ProjectionPredicate<'_>]) -> fmt::Result { @@ -692,7 +692,7 @@ pub fn identify_regions() -> bool { } pub fn parameterized(f: &mut F, - substs: &subst::Substs<'_>, + substs: SubstsRef<'_>, did: DefId, projections: &[ty::ProjectionPredicate<'_>]) -> fmt::Result { @@ -1074,10 +1074,10 @@ define_print! { } write!(f, "fn")?; - cx.fn_sig(f, self.inputs(), self.variadic, self.output()) + cx.fn_sig(f, self.inputs(), self.c_variadic, self.output()) } debug { - write!(f, "({:?}; variadic: {})->{:?}", self.inputs(), self.variadic, self.output()) + write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output()) } } } @@ -1290,7 +1290,7 @@ define_print! { Ok(()) } } - Foreign(def_id) => parameterized(f, subst::Substs::empty(), def_id, &[]), + Foreign(def_id) => parameterized(f, subst::InternalSubsts::empty(), def_id, &[]), Projection(ref data) => data.print(f, cx), UnnormalizedProjection(ref data) => { write!(f, "Unnormalized(")?; diff --git a/src/librustc_apfloat/lib.rs b/src/librustc_apfloat/lib.rs index 46d046d7b41b4..1b0bcdd0b5b48 100644 --- a/src/librustc_apfloat/lib.rs +++ b/src/librustc_apfloat/lib.rs @@ -35,7 +35,6 @@ #![deny(rust_2018_idioms)] #![feature(nll)] -#![feature(try_from)] // See librustc_cratesio_shim/Cargo.toml for a comment explaining this. #[allow(unused_extern_crates)] extern crate rustc_cratesio_shim; diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index b528967dd65ff..c74d7f00cf516 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -89,15 +89,14 @@ struct CheckLoanCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { debug!("consume(consume_id={}, cmt={:?}, mode={:?})", consume_id, cmt, mode); - let hir_id = self.tcx().hir().node_to_hir_id(consume_id); - self.consume_common(hir_id.local_id, consume_span, cmt, mode); + self.consume_common(consume_id.local_id, consume_span, cmt, mode); } fn matched_pat(&mut self, @@ -118,7 +117,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { } fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, @@ -130,22 +129,21 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { borrow_id, cmt, loan_region, bk, loan_cause); - let hir_id = self.tcx().hir().node_to_hir_id(borrow_id); if let Some(lp) = opt_loan_path(cmt) { let moved_value_use_kind = match loan_cause { euv::ClosureCapture(_) => MovedInCapture, _ => MovedInUse, }; - self.check_if_path_is_moved(hir_id.local_id, borrow_span, moved_value_use_kind, &lp); + self.check_if_path_is_moved(borrow_id.local_id, borrow_span, moved_value_use_kind, &lp); } - self.check_for_conflicting_loans(hir_id.local_id); + self.check_for_conflicting_loans(borrow_id.local_id); self.check_for_loans_across_yields(cmt, loan_region, borrow_span); } fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, mode: euv::MutateMode) @@ -176,8 +174,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for CheckLoanCtxt<'a, 'tcx> { } } } - self.check_assignment(self.tcx().hir().node_to_hir_id(assignment_id).local_id, - assignment_span, assignee_cmt); + self.check_assignment(assignment_id.local_id, assignment_span, assignee_cmt); } fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) { } @@ -188,7 +185,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, move_data: &move_data::FlowedMoveData<'c, 'tcx>, all_loans: &[Loan<'tcx>], body: &hir::Body) { - debug!("check_loans(body id={})", body.value.id); + debug!("check_loans(body id={})", body.value.hir_id); let def_id = bccx.tcx.hir().body_owner_def_id(body.id()); diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index cf6053b71b6a8..03af27997d3cb 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -68,7 +68,7 @@ struct GatherLoanCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { fn consume(&mut self, - consume_id: ast::NodeId, + consume_id: hir::HirId, _consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode) { @@ -79,7 +79,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { euv::Move(move_reason) => { gather_moves::gather_move_from_expr( self.bccx, &self.move_data, &mut self.move_error_collector, - self.bccx.tcx.hir().node_to_hir_id(consume_id).local_id, cmt, move_reason); + consume_id.local_id, cmt, move_reason); } euv::Copy => { } } @@ -115,7 +115,7 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { } fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, borrow_span: Span, cmt: &mc::cmt_<'tcx>, loan_region: ty::Region<'tcx>, @@ -126,8 +126,8 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { bk={:?}, loan_cause={:?})", borrow_id, cmt, loan_region, bk, loan_cause); - let hir_id = self.bccx.tcx.hir().node_to_hir_id(borrow_id); - self.guarantee_valid(hir_id.local_id, + + self.guarantee_valid(borrow_id.local_id, borrow_span, cmt, bk, @@ -136,12 +136,13 @@ impl<'a, 'tcx> euv::Delegate<'tcx> for GatherLoanCtxt<'a, 'tcx> { } fn mutate(&mut self, - assignment_id: ast::NodeId, + assignment_id: hir::HirId, assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, _: euv::MutateMode) { - self.guarantee_assignment_valid(assignment_id, + let node_id = self.bccx.tcx.hir().hir_to_node_id(assignment_id); + self.guarantee_assignment_valid(node_id, assignment_span, assignee_cmt); } diff --git a/src/librustc_codegen_llvm/abi.rs b/src/librustc_codegen_llvm/abi.rs index 992149f7a47b5..49c9555a2c682 100644 --- a/src/librustc_codegen_llvm/abi.rs +++ b/src/librustc_codegen_llvm/abi.rs @@ -258,7 +258,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); } @@ -422,7 +422,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { let mut inputs = sig.inputs(); let extra_args = if sig.abi == RustCall { - assert!(!sig.variadic && extra_args.is_empty()); + assert!(!sig.c_variadic && extra_args.is_empty()); match sig.inputs().last().unwrap().sty { ty::Tuple(ref tupled_arguments) => { @@ -435,7 +435,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { } } } else { - assert!(sig.variadic || extra_args.is_empty()); + assert!(sig.c_variadic || extra_args.is_empty()); extra_args }; @@ -507,6 +507,14 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { } }; + // 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); @@ -516,7 +524,30 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { // 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; + 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 `VaList` + // 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.sty { + ty::Adt(def, _) if def.did == va_list_did => { + // This is the "spoofed" `VaList`. Set the arguments mode + // so that it will be ignored. + arg.mode = PassMode::Ignore(IgnoreMode::CVarArgs); + }, + _ => (), + } + } + _ => {} } } @@ -558,7 +589,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { args: inputs.iter().chain(extra_args).enumerate().map(|(i, ty)| { arg_of(ty, Some(i)) }).collect(), - variadic: sig.variadic, + c_variadic: sig.c_variadic, conv, }; fn_ty.adjust_for_abi(cx, sig.abi); @@ -646,7 +677,9 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { ); let llreturn_ty = match self.ret.mode { - PassMode::Ignore => cx.type_void(), + PassMode::Ignore(IgnoreMode::Zst) => cx.type_void(), + PassMode::Ignore(IgnoreMode::CVarArgs) => + bug!("`va_list` should never be a return type"), PassMode::Direct(_) | PassMode::Pair(..) => { self.ret.layout.immediate_llvm_type(cx) } @@ -664,7 +697,7 @@ impl<'tcx> FnTypeExt<'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)); @@ -684,7 +717,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { llargument_tys.push(llarg_ty); } - if self.variadic { + if self.c_variadic { cx.type_variadic_func(&llargument_tys, llreturn_ty) } else { cx.type_func(&llargument_tys, llreturn_ty) @@ -733,7 +766,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { apply(&ArgAttributes::new()); } match arg.mode { - PassMode::Ignore => {} + PassMode::Ignore(_) => {} PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => apply(attrs), PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => { @@ -780,7 +813,7 @@ impl<'tcx> FnTypeExt<'tcx> for FnType<'tcx, Ty<'tcx>> { apply(&ArgAttributes::new()); } match arg.mode { - PassMode::Ignore => {} + PassMode::Ignore(_) => {} PassMode::Direct(ref attrs) | PassMode::Indirect(ref attrs, None) => apply(attrs), PassMode::Indirect(ref attrs, Some(ref extra_attrs)) => { diff --git a/src/librustc_codegen_llvm/debuginfo/mod.rs b/src/librustc_codegen_llvm/debuginfo/mod.rs index ae6e16b31e7aa..c0869bb889afa 100644 --- a/src/librustc_codegen_llvm/debuginfo/mod.rs +++ b/src/librustc_codegen_llvm/debuginfo/mod.rs @@ -15,7 +15,7 @@ use crate::llvm::debuginfo::{DIFile, DIType, DIScope, DIBuilder, DISubprogram, D DISPFlags, DILexicalBlock}; use rustc::hir::CodegenFnAttrFlags; use rustc::hir::def_id::{DefId, CrateNum, LOCAL_CRATE}; -use rustc::ty::subst::{Substs, UnpackedKind}; +use rustc::ty::subst::{SubstsRef, UnpackedKind}; use crate::abi::Abi; use crate::common::CodegenCx; @@ -399,7 +399,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> { fn get_template_parameters<'ll, 'tcx>( cx: &CodegenCx<'ll, 'tcx>, generics: &ty::Generics, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, file_metadata: &'ll DIFile, name_to_append_suffix_to: &mut String, ) -> &'ll DIArray { diff --git a/src/librustc_codegen_llvm/debuginfo/type_names.rs b/src/librustc_codegen_llvm/debuginfo/type_names.rs index 32e930ac44c85..8b218ab39d99b 100644 --- a/src/librustc_codegen_llvm/debuginfo/type_names.rs +++ b/src/librustc_codegen_llvm/debuginfo/type_names.rs @@ -2,7 +2,7 @@ use crate::common::CodegenCx; use rustc::hir::def_id::DefId; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty}; use rustc_codegen_ssa::traits::*; @@ -143,7 +143,7 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, output.pop(); } - if sig.variadic { + if sig.c_variadic { if !sig.inputs().is_empty() { output.push_str(", ..."); } else { @@ -193,13 +193,13 @@ pub fn push_debuginfo_type_name<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, } } - // Pushes the type parameters in the given `Substs` to the output string. + // Pushes the type parameters in the given `InternalSubsts` to the output string. // This ignores region parameters, since they can't reliably be // reconstructed for items from non-local crates. For local crates, this // would be possible but with inlining and LTO we have to use the least // common denominator - otherwise we would run into conflicts. fn push_type_params<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, output: &mut String) { if substs.types().next().is_none() { return; diff --git a/src/librustc_codegen_llvm/intrinsic.rs b/src/librustc_codegen_llvm/intrinsic.rs index d1cbe1d4dd686..3268af396a2f4 100644 --- a/src/librustc_codegen_llvm/intrinsic.rs +++ b/src/librustc_codegen_llvm/intrinsic.rs @@ -136,22 +136,18 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { let tp_ty = substs.type_at(0); self.const_usize(self.size_of(tp_ty).bytes()) } - func @ "va_start" | func @ "va_end" => { - let va_list = match (tcx.lang_items().va_list(), &result.layout.ty.sty) { - (Some(did), ty::Adt(def, _)) if def.did == did => args[0].immediate(), - (Some(_), _) => self.load(args[0].immediate(), - tcx.data_layout.pointer_align.abi), - (None, _) => bug!("va_list language item must be defined") - }; - let intrinsic = self.cx().get_intrinsic(&format!("llvm.{}", func)); - self.call(intrinsic, &[va_list], None) + "va_start" => { + self.va_start(args[0].immediate()) + } + "va_end" => { + self.va_end(args[0].immediate()) } "va_copy" => { let va_list = match (tcx.lang_items().va_list(), &result.layout.ty.sty) { (Some(did), ty::Adt(def, _)) if def.did == did => args[0].immediate(), (Some(_), _) => self.load(args[0].immediate(), tcx.data_layout.pointer_align.abi), - (None, _) => bug!("va_list language item must be defined") + (None, _) => bug!("`va_list` language item must be defined") }; let intrinsic = self.cx().get_intrinsic(&("llvm.va_copy")); self.call(intrinsic, &[llresult, va_list], None); @@ -722,6 +718,41 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> { let expect = self.get_intrinsic(&"llvm.expect.i1"); self.call(expect, &[cond, self.const_bool(expected)], None) } + + fn va_start(&mut self, list: &'ll Value) -> &'ll Value { + let target = &self.cx.tcx.sess.target.target; + let arch = &target.arch; + // A pointer to the architecture specific structure is passed to this + // function. For pointer variants (i686, RISC-V, Windows, etc), we + // should do do nothing, as the address to the pointer is needed. For + // architectures with a architecture specific structure (`Aarch64`, + // `X86_64`, etc), this function should load the structure from the + // address provided. + let va_list = match &**arch { + _ if target.options.is_like_windows => list, + "aarch64" if target.target_os == "ios" => list, + "aarch64" | "x86_64" | "powerpc" => + self.load(list, self.tcx().data_layout.pointer_align.abi), + _ => list, + }; + let intrinsic = self.cx().get_intrinsic("llvm.va_start"); + self.call(intrinsic, &[va_list], None) + } + + fn va_end(&mut self, list: &'ll Value) -> &'ll Value { + let target = &self.cx.tcx.sess.target.target; + let arch = &target.arch; + // See the comment in `va_start` for the purpose of the following. + let va_list = match &**arch { + _ if target.options.is_like_windows => list, + "aarch64" if target.target_os == "ios" => list, + "aarch64" | "x86_64" | "powerpc" => + self.load(list, self.tcx().data_layout.pointer_align.abi), + _ => list, + }; + let intrinsic = self.cx().get_intrinsic("llvm.va_end"); + self.call(intrinsic, &[va_list], None) + } } fn copy_intrinsic( diff --git a/src/librustc_codegen_llvm/mono_item.rs b/src/librustc_codegen_llvm/mono_item.rs index 4fe6a1f4f4b1c..7f0cdb9f58008 100644 --- a/src/librustc_codegen_llvm/mono_item.rs +++ b/src/librustc_codegen_llvm/mono_item.rs @@ -36,10 +36,10 @@ impl PreDefineMethods<'tcx> for CodegenCx<'ll, 'tcx> { } fn predefine_fn(&self, - instance: Instance<'tcx>, - linkage: Linkage, - visibility: Visibility, - symbol_name: &str) { + instance: Instance<'tcx>, + linkage: Linkage, + visibility: Visibility, + symbol_name: &str) { assert!(!instance.substs.needs_infer() && !instance.substs.has_param_types()); diff --git a/src/librustc_codegen_llvm/va_arg.rs b/src/librustc_codegen_llvm/va_arg.rs index 8719390b51aca..7aceaea4510ce 100644 --- a/src/librustc_codegen_llvm/va_arg.rs +++ b/src/librustc_codegen_llvm/va_arg.rs @@ -109,12 +109,12 @@ pub(super) fn emit_va_arg( Align::from_bytes(4).unwrap(), true) } // Windows Aarch64 - ("aarch4", true) => { + ("aarch64", true) => { emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), false) } // iOS Aarch64 - ("aarch4", _) if target.target_os == "ios" => { + ("aarch64", _) if target.target_os == "ios" => { emit_ptr_va_arg(bx, addr, target_ty, false, Align::from_bytes(8).unwrap(), true) } diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index 16f5880b13f5b..4b01e264f19ed 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -11,7 +11,7 @@ use rustc::middle::exported_symbols::{SymbolExportLevel, ExportedSymbol, metadat use rustc::session::config; use rustc::ty::{TyCtxt, SymbolName}; use rustc::ty::query::Providers; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::util::nodemap::{FxHashMap, DefIdMap}; use rustc_allocator::ALLOCATOR_METHODS; use rustc_data_structures::indexed_vec::IndexVec; @@ -282,7 +282,7 @@ fn exported_symbols_provider_local<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn upstream_monomorphizations_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, cnum: CrateNum) - -> Lrc, CrateNum>>>> + -> Lrc, CrateNum>>>> { debug_assert!(cnum == LOCAL_CRATE); @@ -334,7 +334,7 @@ fn upstream_monomorphizations_provider<'a, 'tcx>( fn upstream_monomorphizations_for_provider<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) - -> Option, CrateNum>>> + -> Option, CrateNum>>> { debug_assert!(!def_id.is_local()); tcx.upstream_monomorphizations(LOCAL_CRATE) diff --git a/src/librustc_codegen_ssa/callee.rs b/src/librustc_codegen_ssa/callee.rs index 3665d45d1e9c7..4744dd6302fb3 100644 --- a/src/librustc_codegen_ssa/callee.rs +++ b/src/librustc_codegen_ssa/callee.rs @@ -1,12 +1,12 @@ use crate::traits::*; use rustc::ty; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::hir::def_id::DefId; pub fn resolve_and_get_fn<'tcx, Cx: CodegenMethods<'tcx>>( cx: &Cx, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> Cx::Value { cx.get_fn( ty::Instance::resolve( @@ -23,7 +23,7 @@ pub fn resolve_and_get_fn_for_vtable<'tcx, >( cx: &Cx, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> Cx::Value { cx.get_fn( ty::Instance::resolve_for_vtable( diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index caca1789fc98c..627380ee38ff1 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -3,7 +3,7 @@ use rustc::ty::{self, Ty, TypeFoldable}; use rustc::ty::layout::{self, LayoutOf, HasTyCtxt}; use rustc::mir; use rustc::mir::interpret::EvalErrorKind; -use rustc_target::abi::call::{ArgType, FnType, PassMode}; +use rustc_target::abi::call::{ArgType, FnType, PassMode, IgnoreMode}; use rustc_target::spec::abi::Abi; use rustc_mir::monomorphize; use crate::base; @@ -13,730 +13,872 @@ use crate::meth; use crate::traits::*; +use std::borrow::Cow; + use syntax::symbol::Symbol; use syntax_pos::Pos; use super::{FunctionCx, LocalRef}; use super::place::PlaceRef; -use super::operand::OperandRef; +use super::operand::{OperandValue, OperandRef}; use super::operand::OperandValue::{Pair, Ref, Immediate}; -impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn codegen_block( - &mut self, - bb: mir::BasicBlock, - ) { - let mut bx = self.build_block(bb); - let data = &self.mir[bb]; +/// Used by `FunctionCx::codegen_terminator` for emitting common patterns +/// e.g., creating a basic block, calling a function, etc. +struct TerminatorCodegenHelper<'a, 'tcx> { + bb: &'a mir::BasicBlock, + terminator: &'a mir::Terminator<'tcx>, + funclet_bb: Option, +} - debug!("codegen_block({:?}={:?})", bb, data); +impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> { + /// Returns the associated funclet from `FunctionCx::funclets` for the + /// `funclet_bb` member if it is not `None`. + fn funclet<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>( + &self, + fx: &'c mut FunctionCx<'b, 'tcx, Bx>, + ) -> Option<&'c Bx::Funclet> { + match self.funclet_bb { + Some(funcl) => fx.funclets[funcl].as_ref(), + None => None, + } + } - for statement in &data.statements { - bx = self.codegen_statement(bx, statement); + fn lltarget<'b, 'c, Bx: BuilderMethods<'b, 'tcx>>( + &self, + fx: &'c mut FunctionCx<'b, 'tcx, Bx>, + target: mir::BasicBlock, + ) -> (Bx::BasicBlock, bool) { + let span = self.terminator.source_info.span; + let lltarget = fx.blocks[target]; + let target_funclet = fx.cleanup_kinds[target].funclet_bb(target); + match (self.funclet_bb, target_funclet) { + (None, None) => (lltarget, false), + (Some(f), Some(t_f)) if f == t_f || !base::wants_msvc_seh(fx.cx.tcx().sess) => + (lltarget, false), + // jump *into* cleanup - need a landing pad if GNU + (None, Some(_)) => (fx.landing_pad_to(target), false), + (Some(_), None) => span_bug!(span, "{:?} - jump out of cleanup?", self.terminator), + (Some(_), Some(_)) => (fx.landing_pad_to(target), true), } + } - self.codegen_terminator(bx, bb, data.terminator()); + /// Create a basic block. + fn llblock<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>( + &self, + fx: &'c mut FunctionCx<'b, 'tcx, Bx>, + target: mir::BasicBlock, + ) -> Bx::BasicBlock { + let (lltarget, is_cleanupret) = self.lltarget(fx, target); + if is_cleanupret { + // MSVC cross-funclet jump - need a trampoline + + debug!("llblock: creating cleanup trampoline for {:?}", target); + let name = &format!("{:?}_cleanup_trampoline_{:?}", self.bb, target); + let mut trampoline = fx.new_block(name); + trampoline.cleanup_ret(self.funclet(fx).unwrap(), + Some(lltarget)); + trampoline.llbb() + } else { + lltarget + } } - fn codegen_terminator( - &mut self, - mut bx: Bx, - bb: mir::BasicBlock, - terminator: &mir::Terminator<'tcx> + fn funclet_br<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>( + &self, + fx: &'c mut FunctionCx<'b, 'tcx, Bx>, + bx: &mut Bx, + target: mir::BasicBlock, ) { - debug!("codegen_terminator: {:?}", terminator); - - // Create the cleanup bundle, if needed. - let tcx = self.cx.tcx(); - let span = terminator.source_info.span; - let funclet_bb = self.cleanup_kinds[bb].funclet_bb(bb); + let (lltarget, is_cleanupret) = self.lltarget(fx, target); + if is_cleanupret { + // micro-optimization: generate a `ret` rather than a jump + // to a trampoline. + bx.cleanup_ret(self.funclet(fx).unwrap(), Some(lltarget)); + } else { + bx.br(lltarget); + } + } - // HACK(eddyb) force the right lifetimes, NLL can't figure them out. - fn funclet_closure_factory<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( - funclet_bb: Option - ) -> impl for<'b> Fn( - &'b FunctionCx<'a, 'tcx, Bx>, - ) -> Option<&'b Bx::Funclet> { - move |this| { - match funclet_bb { - Some(funclet_bb) => this.funclets[funclet_bb].as_ref(), - None => None, - } + /// Call `fn_ptr` of `fn_ty` with the arguments `llargs`, the optional + /// return destination `destination` and the cleanup function `cleanup`. + fn do_call<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>( + &self, + fx: &'c mut FunctionCx<'b, 'tcx, Bx>, + bx: &mut Bx, + fn_ty: FnType<'tcx, Ty<'tcx>>, + fn_ptr: Bx::Value, + llargs: &[Bx::Value], + destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>, + cleanup: Option, + ) { + if let Some(cleanup) = cleanup { + let ret_bx = if let Some((_, target)) = destination { + fx.blocks[target] + } else { + fx.unreachable_block() + }; + let invokeret = bx.invoke(fn_ptr, + &llargs, + ret_bx, + self.llblock(fx, cleanup), + self.funclet(fx)); + bx.apply_attrs_callsite(&fn_ty, invokeret); + + if let Some((ret_dest, target)) = destination { + let mut ret_bx = fx.build_block(target); + fx.set_debug_loc(&mut ret_bx, self.terminator.source_info); + fx.store_return(&mut ret_bx, ret_dest, &fn_ty.ret, invokeret); } - } - let funclet = funclet_closure_factory(funclet_bb); - - let lltarget = |this: &mut Self, target: mir::BasicBlock| { - let lltarget = this.blocks[target]; - let target_funclet = this.cleanup_kinds[target].funclet_bb(target); - match (funclet_bb, target_funclet) { - (None, None) => (lltarget, false), - (Some(f), Some(t_f)) - if f == t_f || !base::wants_msvc_seh(tcx.sess) - => (lltarget, false), - (None, Some(_)) => { - // jump *into* cleanup - need a landing pad if GNU - (this.landing_pad_to(target), false) - } - (Some(_), None) => span_bug!(span, "{:?} - jump out of cleanup?", terminator), - (Some(_), Some(_)) => { - (this.landing_pad_to(target), true) - } + } else { + let llret = bx.call(fn_ptr, &llargs, self.funclet(fx)); + bx.apply_attrs_callsite(&fn_ty, llret); + if fx.mir[*self.bb].is_cleanup { + // Cleanup is always the cold path. Don't inline + // drop glue. Also, when there is a deeply-nested + // struct, there are "symmetry" issues that cause + // exponential inlining - see issue #41696. + bx.do_not_inline(llret); } - }; - - let llblock = |this: &mut Self, target: mir::BasicBlock| { - let (lltarget, is_cleanupret) = lltarget(this, target); - if is_cleanupret { - // MSVC cross-funclet jump - need a trampoline - debug!("llblock: creating cleanup trampoline for {:?}", target); - let name = &format!("{:?}_cleanup_trampoline_{:?}", bb, target); - let mut trampoline = this.new_block(name); - trampoline.cleanup_ret(funclet(this).unwrap(), Some(lltarget)); - trampoline.llbb() + if let Some((ret_dest, target)) = destination { + fx.store_return(bx, ret_dest, &fn_ty.ret, llret); + self.funclet_br(fx, bx, target); } else { - lltarget + bx.unreachable(); } - }; - - let funclet_br = - |this: &mut Self, bx: &mut Bx, target: mir::BasicBlock| { - let (lltarget, is_cleanupret) = lltarget(this, target); - if is_cleanupret { - // micro-optimization: generate a `ret` rather than a jump - // to a trampoline. - bx.cleanup_ret(funclet(this).unwrap(), Some(lltarget)); - } else { - bx.br(lltarget); - } - }; + } + } +} - let do_call = | - this: &mut Self, - bx: &mut Bx, - fn_ty: FnType<'tcx, Ty<'tcx>>, - fn_ptr: Bx::Value, - llargs: &[Bx::Value], - destination: Option<(ReturnDest<'tcx, Bx::Value>, mir::BasicBlock)>, - cleanup: Option - | { - if let Some(cleanup) = cleanup { - let ret_bx = if let Some((_, target)) = destination { - this.blocks[target] - } else { - this.unreachable_block() - }; - let invokeret = bx.invoke(fn_ptr, - &llargs, - ret_bx, - llblock(this, cleanup), - funclet(this)); - bx.apply_attrs_callsite(&fn_ty, invokeret); - - if let Some((ret_dest, target)) = destination { - let mut ret_bx = this.build_block(target); - this.set_debug_loc(&mut ret_bx, terminator.source_info); - this.store_return(&mut ret_bx, ret_dest, &fn_ty.ret, invokeret); - } +/// Codegen implementations for some terminator variants. +impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { + /// Generates code for a `Resume` terminator. + fn codegen_resume_terminator<'b>( + &mut self, + helper: TerminatorCodegenHelper<'b, 'tcx>, + mut bx: Bx, + ) { + if let Some(funclet) = helper.funclet(self) { + bx.cleanup_ret(funclet, None); + } else { + let slot = self.get_personality_slot(&mut bx); + let lp0 = slot.project_field(&mut bx, 0); + let lp0 = bx.load_operand(lp0).immediate(); + let lp1 = slot.project_field(&mut bx, 1); + let lp1 = bx.load_operand(lp1).immediate(); + slot.storage_dead(&mut bx); + + if !bx.sess().target.target.options.custom_unwind_resume { + let mut lp = bx.const_undef(self.landing_pad_type()); + lp = bx.insert_value(lp, lp0, 0); + lp = bx.insert_value(lp, lp1, 1); + bx.resume(lp); } else { - let llret = bx.call(fn_ptr, &llargs, funclet(this)); - bx.apply_attrs_callsite(&fn_ty, llret); - if this.mir[bb].is_cleanup { - // Cleanup is always the cold path. Don't inline - // drop glue. Also, when there is a deeply-nested - // struct, there are "symmetry" issues that cause - // exponential inlining - see issue #41696. - bx.do_not_inline(llret); - } - - if let Some((ret_dest, target)) = destination { - this.store_return(bx, ret_dest, &fn_ty.ret, llret); - funclet_br(this, bx, target); - } else { - bx.unreachable(); - } + bx.call(bx.eh_unwind_resume(), &[lp0], + helper.funclet(self)); + bx.unreachable(); } - }; + } + } - self.set_debug_loc(&mut bx, terminator.source_info); - match terminator.kind { - mir::TerminatorKind::Resume => { - if let Some(funclet) = funclet(self) { - bx.cleanup_ret(funclet, None); + fn codegen_switchint_terminator<'b>( + &mut self, + helper: TerminatorCodegenHelper<'b, 'tcx>, + mut bx: Bx, + discr: &mir::Operand<'tcx>, + switch_ty: Ty<'tcx>, + values: &Cow<'tcx, [u128]>, + targets: &Vec, + ) { + let discr = self.codegen_operand(&mut bx, &discr); + if targets.len() == 2 { + // If there are two targets, emit br instead of switch + let lltrue = helper.llblock(self, targets[0]); + let llfalse = helper.llblock(self, targets[1]); + if switch_ty == bx.tcx().types.bool { + // Don't generate trivial icmps when switching on bool + if let [0] = values[..] { + bx.cond_br(discr.immediate(), llfalse, lltrue); } else { - let slot = self.get_personality_slot(&mut bx); - let lp0 = slot.project_field(&mut bx, 0); - let lp0 = bx.load_operand(lp0).immediate(); - let lp1 = slot.project_field(&mut bx, 1); - let lp1 = bx.load_operand(lp1).immediate(); - slot.storage_dead(&mut bx); - - if !bx.sess().target.target.options.custom_unwind_resume { - let mut lp = bx.const_undef(self.landing_pad_type()); - lp = bx.insert_value(lp, lp0, 0); - lp = bx.insert_value(lp, lp1, 1); - bx.resume(lp); - } else { - bx.call(bx.eh_unwind_resume(), &[lp0], funclet(self)); - bx.unreachable(); - } + assert_eq!(&values[..], &[1]); + bx.cond_br(discr.immediate(), lltrue, llfalse); } + } else { + let switch_llty = bx.immediate_backend_type( + bx.layout_of(switch_ty) + ); + let llval = bx.const_uint_big(switch_llty, values[0]); + let cmp = bx.icmp(IntPredicate::IntEQ, discr.immediate(), llval); + bx.cond_br(cmp, lltrue, llfalse); + } + } else { + let (otherwise, targets) = targets.split_last().unwrap(); + let switch = bx.switch(discr.immediate(), + helper.llblock(self, *otherwise), + values.len()); + let switch_llty = bx.immediate_backend_type( + bx.layout_of(switch_ty) + ); + for (&value, target) in values.iter().zip(targets) { + let llval = bx.const_uint_big(switch_llty, value); + let llbb = helper.llblock(self, *target); + bx.add_case(switch, llval, llbb) } + } + } - mir::TerminatorKind::Abort => { - bx.abort(); - bx.unreachable(); + fn codegen_return_terminator<'b>( + &mut self, + mut bx: Bx, + ) { + if self.fn_ty.c_variadic { + if let Some(va_list) = self.va_list_ref { + bx.va_end(va_list.llval); + } + } + let llval = match self.fn_ty.ret.mode { + PassMode::Ignore(IgnoreMode::Zst) | PassMode::Indirect(..) => { + bx.ret_void(); + return; } - mir::TerminatorKind::Goto { target } => { - funclet_br(self, &mut bx, target); + PassMode::Ignore(IgnoreMode::CVarArgs) => { + bug!("C-variadic arguments should never be the return type"); } - mir::TerminatorKind::SwitchInt { ref discr, switch_ty, ref values, ref targets } => { - let discr = self.codegen_operand(&mut bx, discr); - if targets.len() == 2 { - // If there are two targets, emit br instead of switch - let lltrue = llblock(self, targets[0]); - let llfalse = llblock(self, targets[1]); - if switch_ty == bx.tcx().types.bool { - // Don't generate trivial icmps when switching on bool - if let [0] = values[..] { - bx.cond_br(discr.immediate(), llfalse, lltrue); - } else { - assert_eq!(&values[..], &[1]); - bx.cond_br(discr.immediate(), lltrue, llfalse); - } - } else { - let switch_llty = bx.immediate_backend_type( - bx.layout_of(switch_ty) - ); - let llval = bx.const_uint_big(switch_llty, values[0]); - let cmp = bx.icmp(IntPredicate::IntEQ, discr.immediate(), llval); - bx.cond_br(cmp, lltrue, llfalse); - } + PassMode::Direct(_) | PassMode::Pair(..) => { + let op = + self.codegen_consume(&mut bx, &mir::Place::Local(mir::RETURN_PLACE)); + if let Ref(llval, _, align) = op.val { + bx.load(llval, align) } else { - let (otherwise, targets) = targets.split_last().unwrap(); - let switch = bx.switch(discr.immediate(), - llblock(self, *otherwise), - values.len()); - let switch_llty = bx.immediate_backend_type( - bx.layout_of(switch_ty) - ); - for (&value, target) in values.iter().zip(targets) { - let llval = bx.const_uint_big(switch_llty, value); - let llbb = llblock(self, *target); - bx.add_case(switch, llval, llbb) - } + op.immediate_or_packed_pair(&mut bx) } } - mir::TerminatorKind::Return => { - let llval = match self.fn_ty.ret.mode { - PassMode::Ignore | PassMode::Indirect(..) => { - bx.ret_void(); - return; - } - - PassMode::Direct(_) | PassMode::Pair(..) => { - let op = - self.codegen_consume(&mut bx, &mir::Place::Local(mir::RETURN_PLACE)); - if let Ref(llval, _, align) = op.val { - bx.load(llval, align) - } else { - op.immediate_or_packed_pair(&mut bx) + PassMode::Cast(cast_ty) => { + let op = match self.locals[mir::RETURN_PLACE] { + LocalRef::Operand(Some(op)) => op, + LocalRef::Operand(None) => bug!("use of return before def"), + LocalRef::Place(cg_place) => { + OperandRef { + val: Ref(cg_place.llval, None, cg_place.align), + layout: cg_place.layout } } - - PassMode::Cast(cast_ty) => { - let op = match self.locals[mir::RETURN_PLACE] { - LocalRef::Operand(Some(op)) => op, - LocalRef::Operand(None) => bug!("use of return before def"), - LocalRef::Place(cg_place) => { - OperandRef { - val: Ref(cg_place.llval, None, cg_place.align), - layout: cg_place.layout - } - } - LocalRef::UnsizedPlace(_) => bug!("return type must be sized"), - }; - let llslot = match op.val { - Immediate(_) | Pair(..) => { - let scratch = - PlaceRef::alloca(&mut bx, self.fn_ty.ret.layout, "ret"); - op.val.store(&mut bx, scratch); - scratch.llval - } - Ref(llval, _, align) => { - assert_eq!(align, op.layout.align.abi, - "return place is unaligned!"); - llval - } - }; - let addr = bx.pointercast(llslot, bx.type_ptr_to( - bx.cast_backend_type(&cast_ty) - )); - bx.load(addr, self.fn_ty.ret.layout.align.abi) + LocalRef::UnsizedPlace(_) => bug!("return type must be sized"), + }; + let llslot = match op.val { + Immediate(_) | Pair(..) => { + let scratch = + PlaceRef::alloca(&mut bx, self.fn_ty.ret.layout, "ret"); + op.val.store(&mut bx, scratch); + scratch.llval + } + Ref(llval, _, align) => { + assert_eq!(align, op.layout.align.abi, + "return place is unaligned!"); + llval } }; - bx.ret(llval); + let addr = bx.pointercast(llslot, bx.type_ptr_to( + bx.cast_backend_type(&cast_ty) + )); + bx.load(addr, self.fn_ty.ret.layout.align.abi) } + }; + bx.ret(llval); + } - mir::TerminatorKind::Unreachable => { - bx.unreachable(); + + fn codegen_drop_terminator<'b>( + &mut self, + helper: TerminatorCodegenHelper<'b, 'tcx>, + mut bx: Bx, + location: &mir::Place<'tcx>, + target: mir::BasicBlock, + unwind: Option, + ) { + let ty = location.ty(self.mir, bx.tcx()).to_ty(bx.tcx()); + let ty = self.monomorphize(&ty); + let drop_fn = monomorphize::resolve_drop_in_place(bx.tcx(), ty); + + if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def { + // we don't actually need to drop anything. + helper.funclet_br(self, &mut bx, target); + return + } + + let place = self.codegen_place(&mut bx, location); + let (args1, args2); + let mut args = if let Some(llextra) = place.llextra { + args2 = [place.llval, llextra]; + &args2[..] + } else { + args1 = [place.llval]; + &args1[..] + }; + let (drop_fn, fn_ty) = match ty.sty { + ty::Dynamic(..) => { + let sig = drop_fn.fn_sig(self.cx.tcx()); + let sig = self.cx.tcx().normalize_erasing_late_bound_regions( + ty::ParamEnv::reveal_all(), + &sig, + ); + let fn_ty = bx.new_vtable(sig, &[]); + let vtable = args[1]; + args = &args[..1]; + (meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty) + } + _ => { + (bx.get_fn(drop_fn), + bx.fn_type_of_instance(&drop_fn)) } + }; + helper.do_call(self, &mut bx, fn_ty, drop_fn, args, + Some((ReturnDest::Nothing, target)), + unwind); + } - mir::TerminatorKind::Drop { ref location, target, unwind } => { - let ty = location.ty(self.mir, bx.tcx()).to_ty(bx.tcx()); - let ty = self.monomorphize(&ty); - let drop_fn = monomorphize::resolve_drop_in_place(bx.tcx(), ty); - - if let ty::InstanceDef::DropGlue(_, None) = drop_fn.def { - // we don't actually need to drop anything. - funclet_br(self, &mut bx, target); - return - } + fn codegen_assert_terminator<'b>( + &mut self, + helper: TerminatorCodegenHelper<'b, 'tcx>, + mut bx: Bx, + terminator: &mir::Terminator<'tcx>, + cond: &mir::Operand<'tcx>, + expected: bool, + msg: &mir::AssertMessage<'tcx>, + target: mir::BasicBlock, + cleanup: Option, + ) { + let span = terminator.source_info.span; + let cond = self.codegen_operand(&mut bx, cond).immediate(); + let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1); + + // This case can currently arise only from functions marked + // with #[rustc_inherit_overflow_checks] and inlined from + // another crate (mostly core::num generic/#[inline] fns), + // while the current crate doesn't use overflow checks. + // NOTE: Unlike binops, negation doesn't have its own + // checked operation, just a comparison with the minimum + // value, so we have to check for the assert message. + if !bx.check_overflow() { + if let mir::interpret::EvalErrorKind::OverflowNeg = *msg { + const_cond = Some(expected); + } + } - let place = self.codegen_place(&mut bx, location); - let (args1, args2); - let mut args = if let Some(llextra) = place.llextra { - args2 = [place.llval, llextra]; - &args2[..] - } else { - args1 = [place.llval]; - &args1[..] - }; - let (drop_fn, fn_ty) = match ty.sty { - ty::Dynamic(..) => { - let sig = drop_fn.fn_sig(tcx); - let sig = tcx.normalize_erasing_late_bound_regions( - ty::ParamEnv::reveal_all(), - &sig, - ); - let fn_ty = bx.new_vtable(sig, &[]); - let vtable = args[1]; - args = &args[..1]; - (meth::DESTRUCTOR.get_fn(&mut bx, vtable, &fn_ty), fn_ty) - } - _ => { - (bx.get_fn(drop_fn), - bx.fn_type_of_instance(&drop_fn)) - } - }; - do_call(self, &mut bx, fn_ty, drop_fn, args, - Some((ReturnDest::Nothing, target)), - unwind); + // Don't codegen the panic block if success if known. + if const_cond == Some(expected) { + helper.funclet_br(self, &mut bx, target); + return; + } + + // Pass the condition through llvm.expect for branch hinting. + let cond = bx.expect(cond, expected); + + // Create the failure block and the conditional branch to it. + let lltarget = helper.llblock(self, target); + let panic_block = self.new_block("panic"); + if expected { + bx.cond_br(cond, lltarget, panic_block.llbb()); + } else { + bx.cond_br(cond, panic_block.llbb(), lltarget); + } + + // After this point, bx is the block for the call to panic. + bx = panic_block; + self.set_debug_loc(&mut bx, terminator.source_info); + + // Get the location information. + let loc = bx.sess().source_map().lookup_char_pos(span.lo()); + let filename = Symbol::intern(&loc.file.name.to_string()).as_str(); + let filename = bx.const_str_slice(filename); + let line = bx.const_u32(loc.line as u32); + let col = bx.const_u32(loc.col.to_usize() as u32 + 1); + let align = self.cx.tcx().data_layout.aggregate_align.abi + .max(self.cx.tcx().data_layout.i32_align.abi) + .max(self.cx.tcx().data_layout.pointer_align.abi); + + // Put together the arguments to the panic entry point. + let (lang_item, args) = match *msg { + EvalErrorKind::BoundsCheck { ref len, ref index } => { + let len = self.codegen_operand(&mut bx, len).immediate(); + let index = self.codegen_operand(&mut bx, index).immediate(); + + let file_line_col = bx.const_struct(&[filename, line, col], false); + let file_line_col = bx.static_addr_of( + file_line_col, + align, + Some("panic_bounds_check_loc") + ); + (lang_items::PanicBoundsCheckFnLangItem, + vec![file_line_col, index, len]) + } + _ => { + let str = msg.description(); + let msg_str = Symbol::intern(str).as_str(); + let msg_str = bx.const_str_slice(msg_str); + let msg_file_line_col = bx.const_struct( + &[msg_str, filename, line, col], + false + ); + let msg_file_line_col = bx.static_addr_of( + msg_file_line_col, + align, + Some("panic_loc") + ); + (lang_items::PanicFnLangItem, + vec![msg_file_line_col]) } + }; - mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => { - let cond = self.codegen_operand(&mut bx, cond).immediate(); - let mut const_cond = bx.const_to_opt_u128(cond, false).map(|c| c == 1); - - // This case can currently arise only from functions marked - // with #[rustc_inherit_overflow_checks] and inlined from - // another crate (mostly core::num generic/#[inline] fns), - // while the current crate doesn't use overflow checks. - // NOTE: Unlike binops, negation doesn't have its own - // checked operation, just a comparison with the minimum - // value, so we have to check for the assert message. - if !bx.check_overflow() { - if let mir::interpret::EvalErrorKind::OverflowNeg = *msg { - const_cond = Some(expected); - } - } + // Obtain the panic entry point. + let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item); + let instance = ty::Instance::mono(bx.tcx(), def_id); + let fn_ty = bx.fn_type_of_instance(&instance); + let llfn = bx.get_fn(instance); - // Don't codegen the panic block if success if known. - if const_cond == Some(expected) { - funclet_br(self, &mut bx, target); - return; - } + // Codegen the actual panic invoke/call. + helper.do_call(self, &mut bx, fn_ty, llfn, &args, None, cleanup); + } - // Pass the condition through llvm.expect for branch hinting. - let cond = bx.expect(cond, expected); + fn codegen_call_terminator<'b>( + &mut self, + helper: TerminatorCodegenHelper<'b, 'tcx>, + mut bx: Bx, + terminator: &mir::Terminator<'tcx>, + func: &mir::Operand<'tcx>, + args: &Vec>, + destination: &Option<(mir::Place<'tcx>, mir::BasicBlock)>, + cleanup: Option, + ) { + let span = terminator.source_info.span; + // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar. + let callee = self.codegen_operand(&mut bx, func); + + let (instance, mut llfn) = match callee.layout.ty.sty { + ty::FnDef(def_id, substs) => { + (Some(ty::Instance::resolve(bx.tcx(), + ty::ParamEnv::reveal_all(), + def_id, + substs).unwrap()), + None) + } + ty::FnPtr(_) => { + (None, Some(callee.immediate())) + } + _ => bug!("{} is not callable", callee.layout.ty), + }; + let def = instance.map(|i| i.def); + let sig = callee.layout.ty.fn_sig(bx.tcx()); + let sig = bx.tcx().normalize_erasing_late_bound_regions( + ty::ParamEnv::reveal_all(), + &sig, + ); + let abi = sig.abi; + + // Handle intrinsics old codegen wants Expr's for, ourselves. + let intrinsic = match def { + Some(ty::InstanceDef::Intrinsic(def_id)) => + Some(bx.tcx().item_name(def_id).as_str()), + _ => None + }; + let intrinsic = intrinsic.as_ref().map(|s| &s[..]); - // Create the failure block and the conditional branch to it. - let lltarget = llblock(self, target); - let panic_block = self.new_block("panic"); - if expected { - bx.cond_br(cond, lltarget, panic_block.llbb()); - } else { - bx.cond_br(cond, panic_block.llbb(), lltarget); - } + if intrinsic == Some("transmute") { + if let Some(destination_ref) = destination.as_ref() { + let &(ref dest, target) = destination_ref; + self.codegen_transmute(&mut bx, &args[0], dest); + helper.funclet_br(self, &mut bx, target); + } else { + // If we are trying to transmute to an uninhabited type, + // it is likely there is no allotted destination. In fact, + // transmuting to an uninhabited type is UB, which means + // we can do what we like. Here, we declare that transmuting + // into an uninhabited type is impossible, so anything following + // it must be unreachable. + assert_eq!(bx.layout_of(sig.output()).abi, layout::Abi::Uninhabited); + bx.unreachable(); + } + return; + } - // After this point, bx is the block for the call to panic. - bx = panic_block; - self.set_debug_loc(&mut bx, terminator.source_info); + // The "spoofed" `VaList` 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 = extra_args.iter().map(|op_arg| { + let op_ty = op_arg.ty(self.mir, bx.tcx()); + self.monomorphize(&op_ty) + }).collect::>(); + + let fn_ty = match def { + Some(ty::InstanceDef::Virtual(..)) => { + bx.new_vtable(sig, &extra_args) + } + Some(ty::InstanceDef::DropGlue(_, None)) => { + // Empty drop glue; a no-op. + let &(_, target) = destination.as_ref().unwrap(); + helper.funclet_br(self, &mut bx, target); + return; + } + _ => bx.new_fn_type(sig, &extra_args) + }; - // Get the location information. + // Emit a panic or a no-op for `panic_if_uninhabited`. + if intrinsic == Some("panic_if_uninhabited") { + let ty = instance.unwrap().substs.type_at(0); + let layout = bx.layout_of(ty); + if layout.abi.is_uninhabited() { let loc = bx.sess().source_map().lookup_char_pos(span.lo()); let filename = Symbol::intern(&loc.file.name.to_string()).as_str(); let filename = bx.const_str_slice(filename); let line = bx.const_u32(loc.line as u32); let col = bx.const_u32(loc.col.to_usize() as u32 + 1); - let align = tcx.data_layout.aggregate_align.abi - .max(tcx.data_layout.i32_align.abi) - .max(tcx.data_layout.pointer_align.abi); - - // Put together the arguments to the panic entry point. - let (lang_item, args) = match *msg { - EvalErrorKind::BoundsCheck { ref len, ref index } => { - let len = self.codegen_operand(&mut bx, len).immediate(); - let index = self.codegen_operand(&mut bx, index).immediate(); - - let file_line_col = bx.const_struct(&[filename, line, col], false); - let file_line_col = bx.static_addr_of( - file_line_col, - align, - Some("panic_bounds_check_loc") - ); - (lang_items::PanicBoundsCheckFnLangItem, - vec![file_line_col, index, len]) - } - _ => { - let str = msg.description(); - let msg_str = Symbol::intern(str).as_str(); - let msg_str = bx.const_str_slice(msg_str); - let msg_file_line_col = bx.const_struct( - &[msg_str, filename, line, col], - false - ); - let msg_file_line_col = bx.static_addr_of( - msg_file_line_col, - align, - Some("panic_loc") - ); - (lang_items::PanicFnLangItem, - vec![msg_file_line_col]) - } - }; + let align = self.cx.tcx().data_layout.aggregate_align.abi + .max(self.cx.tcx().data_layout.i32_align.abi) + .max(self.cx.tcx().data_layout.pointer_align.abi); + + let str = format!( + "Attempted to instantiate uninhabited type {}", + ty + ); + let msg_str = Symbol::intern(&str).as_str(); + let msg_str = bx.const_str_slice(msg_str); + let msg_file_line_col = bx.const_struct( + &[msg_str, filename, line, col], + false, + ); + let msg_file_line_col = bx.static_addr_of( + msg_file_line_col, + align, + Some("panic_loc"), + ); // Obtain the panic entry point. - let def_id = common::langcall(bx.tcx(), Some(span), "", lang_item); + let def_id = + common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem); let instance = ty::Instance::mono(bx.tcx(), def_id); let fn_ty = bx.fn_type_of_instance(&instance); let llfn = bx.get_fn(instance); // Codegen the actual panic invoke/call. - do_call(self, &mut bx, fn_ty, llfn, &args, None, cleanup); + helper.do_call( + self, + &mut bx, + fn_ty, + llfn, + &[msg_file_line_col], + destination.as_ref().map(|(_, bb)| (ReturnDest::Nothing, *bb)), + cleanup, + ); + } else { + // a NOP + helper.funclet_br(self, &mut bx, destination.as_ref().unwrap().1) } + return; + } - mir::TerminatorKind::DropAndReplace { .. } => { - bug!("undesugared DropAndReplace in codegen: {:?}", terminator); - } + // The arguments we'll be passing. Plus one to account for outptr, if used. + let arg_count = fn_ty.args.len() + fn_ty.ret.is_indirect() as usize; + let mut llargs = Vec::with_capacity(arg_count); - mir::TerminatorKind::Call { - ref func, - ref args, - ref destination, - cleanup, - from_hir_call: _ - } => { - // Create the callee. This is a fn ptr or zero-sized and hence a kind of scalar. - let callee = self.codegen_operand(&mut bx, func); - - let (instance, mut llfn) = match callee.layout.ty.sty { - ty::FnDef(def_id, substs) => { - (Some(ty::Instance::resolve(bx.tcx(), - ty::ParamEnv::reveal_all(), - def_id, - substs).unwrap()), - None) - } - ty::FnPtr(_) => { - (None, Some(callee.immediate())) - } - _ => bug!("{} is not callable", callee.layout.ty) - }; - let def = instance.map(|i| i.def); - let sig = callee.layout.ty.fn_sig(bx.tcx()); - let sig = bx.tcx().normalize_erasing_late_bound_regions( - ty::ParamEnv::reveal_all(), - &sig, - ); - let abi = sig.abi; + // Prepare the return value destination + let ret_dest = if let Some((ref dest, _)) = *destination { + let is_intrinsic = intrinsic.is_some(); + self.make_return_dest(&mut bx, dest, &fn_ty.ret, &mut llargs, + is_intrinsic) + } else { + ReturnDest::Nothing + }; - // Handle intrinsics old codegen wants Expr's for, ourselves. - let intrinsic = match def { - Some(ty::InstanceDef::Intrinsic(def_id)) - => Some(bx.tcx().item_name(def_id).as_str()), - _ => None - }; - let intrinsic = intrinsic.as_ref().map(|s| &s[..]); + if intrinsic.is_some() && intrinsic != Some("drop_in_place") { + let dest = match ret_dest { + _ if fn_ty.ret.is_indirect() => llargs[0], + ReturnDest::Nothing => + bx.const_undef(bx.type_ptr_to(bx.memory_ty(&fn_ty.ret))), + ReturnDest::IndirectOperand(dst, _) | ReturnDest::Store(dst) => + dst.llval, + ReturnDest::DirectOperand(_) => + bug!("Cannot use direct operand with an intrinsic call"), + }; - if intrinsic == Some("transmute") { - if let Some(destination_ref) = destination.as_ref() { - let &(ref dest, target) = destination_ref; - self.codegen_transmute(&mut bx, &args[0], dest); - funclet_br(self, &mut bx, target); - } else { - // If we are trying to transmute to an uninhabited type, - // it is likely there is no allotted destination. In fact, - // transmuting to an uninhabited type is UB, which means - // we can do what we like. Here, we declare that transmuting - // into an uninhabited type is impossible, so anything following - // it must be unreachable. - assert_eq!(bx.layout_of(sig.output()).abi, layout::Abi::Uninhabited); - bx.unreachable(); + let args: Vec<_> = args.iter().enumerate().map(|(i, arg)| { + // The indices passed to simd_shuffle* in the + // third argument must be constant. This is + // checked by const-qualification, which also + // promotes any complex rvalues to constants. + if i == 2 && intrinsic.unwrap().starts_with("simd_shuffle") { + match *arg { + // The shuffle array argument is usually not an explicit constant, + // but specified directly in the code. This means it gets promoted + // and we can then extract the value by evaluating the promoted. + mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) | + mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => { + let param_env = ty::ParamEnv::reveal_all(); + let cid = mir::interpret::GlobalId { + instance: self.instance, + promoted: Some(index), + }; + let c = bx.tcx().const_eval(param_env.and(cid)); + let (llval, ty) = self.simd_shuffle_indices( + &bx, + terminator.source_info.span, + ty, + c, + ); + return OperandRef { + val: Immediate(llval), + layout: bx.layout_of(ty), + }; + + } + mir::Operand::Copy(_) | + mir::Operand::Move(_) => { + span_bug!(span, "shuffle indices must be constant"); + } + mir::Operand::Constant(ref constant) => { + let c = self.eval_mir_constant(&bx, constant); + let (llval, ty) = self.simd_shuffle_indices( + &bx, + constant.span, + constant.ty, + c, + ); + return OperandRef { + val: Immediate(llval), + layout: bx.layout_of(ty) + }; + } } - return; } - 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) - }).collect::>(); + self.codegen_operand(&mut bx, arg) + }).collect(); - let fn_ty = match def { - Some(ty::InstanceDef::Virtual(..)) => { - bx.new_vtable(sig, &extra_args) - } - Some(ty::InstanceDef::DropGlue(_, None)) => { - // empty drop glue - a nop. - let &(_, target) = destination.as_ref().unwrap(); - funclet_br(self, &mut bx, target); - return; - } - _ => bx.new_fn_type(sig, &extra_args) + + let callee_ty = instance.as_ref().unwrap().ty(bx.tcx()); + bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest, + terminator.source_info.span); + + if let ReturnDest::IndirectOperand(dst, _) = ret_dest { + self.store_return(&mut bx, ret_dest, &fn_ty.ret, dst.llval); + } + + if let Some((_, target)) = *destination { + helper.funclet_br(self, &mut bx, target); + } else { + bx.unreachable(); + } + + return; + } + + // Split the rust-call tupled arguments off. + let (first_args, untuple) = if abi == Abi::RustCall && !args.is_empty() { + let (tup, args) = args.split_last().unwrap(); + (args, Some(tup)) + } else { + (&args[..], None) + }; + + // Useful determining if the current argument is the "spoofed" `VaList` + 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" `VaList`. 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| x == i).unwrap_or(false) { + let layout = match self.cx.tcx().lang_items().va_list() { + Some(did) => bx.cx().layout_of(bx.tcx().type_of(did)), + None => bug!("`va_list` language item required for C-variadics"), }; + let op = OperandRef { + val: OperandValue::Immediate( + bx.cx().const_undef(bx.cx().immediate_backend_type(layout) + )), + layout: layout, + }; + self.codegen_argument(&mut bx, op, &mut llargs, &fn_ty.args[i]); + 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) { + if let Pair(..) = op.val { + // In the case of Rc, we need to explicitly pass a + // *mut RcBox with a Scalar (not ScalarPair) ABI. This is a hack + // that is understood elsewhere in the compiler as a method on + // `dyn Trait`. + // To get a `*mut RcBox`, we just keep unwrapping newtypes until + // we get a value of a built-in pointer type + 'descend_newtypes: while !op.layout.ty.is_unsafe_ptr() + && !op.layout.ty.is_region_ptr() + { + 'iter_fields: for i in 0..op.layout.fields.count() { + let field = op.extract_field(&mut bx, i); + if !field.layout.is_zst() { + // we found the one non-zero-sized field that is allowed + // now find *its* non-zero-sized field, or stop if it's a + // pointer + op = field; + continue 'descend_newtypes + } + } - // emit a panic or a NOP for `panic_if_uninhabited` - if intrinsic == Some("panic_if_uninhabited") { - let ty = instance.unwrap().substs.type_at(0); - let layout = bx.layout_of(ty); - if layout.abi.is_uninhabited() { - let loc = bx.sess().source_map().lookup_char_pos(span.lo()); - let filename = Symbol::intern(&loc.file.name.to_string()).as_str(); - let filename = bx.const_str_slice(filename); - let line = bx.const_u32(loc.line as u32); - let col = bx.const_u32(loc.col.to_usize() as u32 + 1); - let align = tcx.data_layout.aggregate_align.abi - .max(tcx.data_layout.i32_align.abi) - .max(tcx.data_layout.pointer_align.abi); - - let str = format!( - "Attempted to instantiate uninhabited type {}", - ty - ); - let msg_str = Symbol::intern(&str).as_str(); - let msg_str = bx.const_str_slice(msg_str); - let msg_file_line_col = bx.const_struct( - &[msg_str, filename, line, col], - false, - ); - let msg_file_line_col = bx.static_addr_of( - msg_file_line_col, - align, - Some("panic_loc"), - ); - - // Obtain the panic entry point. - let def_id = - common::langcall(bx.tcx(), Some(span), "", lang_items::PanicFnLangItem); - let instance = ty::Instance::mono(bx.tcx(), def_id); - let fn_ty = bx.fn_type_of_instance(&instance); - let llfn = bx.get_fn(instance); - - // Codegen the actual panic invoke/call. - do_call( - self, - &mut bx, - fn_ty, - llfn, - &[msg_file_line_col], - destination.as_ref().map(|(_, bb)| (ReturnDest::Nothing, *bb)), - cleanup, - ); - } else { - // a NOP - funclet_br(self, &mut bx, destination.as_ref().unwrap().1); + span_bug!(span, "receiver has no non-zero-sized fields {:?}", op); } - return; + + // now that we have `*dyn Trait` or `&dyn Trait`, split it up into its + // data pointer and vtable. Look up the method in the vtable, and pass + // the data pointer as the first argument + match op.val { + Pair(data_ptr, meta) => { + llfn = Some(meth::VirtualIndex::from_index(idx) + .get_fn(&mut bx, meta, &fn_ty)); + llargs.push(data_ptr); + continue 'make_args + } + other => bug!("expected a Pair, got {:?}", other), + } + } else if let Ref(data_ptr, Some(meta), _) = op.val { + // by-value dynamic dispatch + llfn = Some(meth::VirtualIndex::from_index(idx) + .get_fn(&mut bx, meta, &fn_ty)); + llargs.push(data_ptr); + continue; + } else { + span_bug!(span, "can't codegen a virtual call on {:?}", op); } + } - // The arguments we'll be passing. Plus one to account for outptr, if used. - let arg_count = fn_ty.args.len() + fn_ty.ret.is_indirect() as usize; - let mut llargs = Vec::with_capacity(arg_count); + // The callee needs to own the argument memory if we pass it + // by-ref, so make a local copy of non-immediate constants. + match (arg, op.val) { + (&mir::Operand::Copy(_), Ref(_, None, _)) | + (&mir::Operand::Constant(_), Ref(_, None, _)) => { + let tmp = PlaceRef::alloca(&mut bx, op.layout, "const"); + op.val.store(&mut bx, tmp); + op.val = Ref(tmp.llval, None, tmp.align); + } + _ => {} + } - // Prepare the return value destination - let ret_dest = if let Some((ref dest, _)) = *destination { - let is_intrinsic = intrinsic.is_some(); - self.make_return_dest(&mut bx, dest, &fn_ty.ret, &mut llargs, - is_intrinsic) - } else { - ReturnDest::Nothing - }; + self.codegen_argument(&mut bx, op, &mut llargs, &fn_ty.args[i]); + } + if let Some(tup) = untuple { + self.codegen_arguments_untupled(&mut bx, tup, &mut llargs, + &fn_ty.args[first_args.len()..]) + } - if intrinsic.is_some() && intrinsic != Some("drop_in_place") { - let dest = match ret_dest { - _ if fn_ty.ret.is_indirect() => llargs[0], - ReturnDest::Nothing => { - bx.const_undef(bx.type_ptr_to(bx.memory_ty(&fn_ty.ret))) - } - ReturnDest::IndirectOperand(dst, _) | - ReturnDest::Store(dst) => dst.llval, - ReturnDest::DirectOperand(_) => - bug!("Cannot use direct operand with an intrinsic call") - }; + let fn_ptr = match (llfn, instance) { + (Some(llfn), _) => llfn, + (None, Some(instance)) => bx.get_fn(instance), + _ => span_bug!(span, "no llfn for call"), + }; - let args: Vec<_> = args.iter().enumerate().map(|(i, arg)| { - // The indices passed to simd_shuffle* in the - // third argument must be constant. This is - // checked by const-qualification, which also - // promotes any complex rvalues to constants. - if i == 2 && intrinsic.unwrap().starts_with("simd_shuffle") { - match *arg { - // The shuffle array argument is usually not an explicit constant, - // but specified directly in the code. This means it gets promoted - // and we can then extract the value by evaluating the promoted. - mir::Operand::Copy(mir::Place::Promoted(box(index, ty))) | - mir::Operand::Move(mir::Place::Promoted(box(index, ty))) => { - let param_env = ty::ParamEnv::reveal_all(); - let cid = mir::interpret::GlobalId { - instance: self.instance, - promoted: Some(index), - }; - let c = bx.tcx().const_eval(param_env.and(cid)); - let (llval, ty) = self.simd_shuffle_indices( - &bx, - terminator.source_info.span, - ty, - c, - ); - return OperandRef { - val: Immediate(llval), - layout: bx.layout_of(ty), - }; - - }, - mir::Operand::Copy(_) | - mir::Operand::Move(_) => { - span_bug!(span, "shuffle indices must be constant"); - } - mir::Operand::Constant(ref constant) => { - let c = self.eval_mir_constant(&bx, constant); - let (llval, ty) = self.simd_shuffle_indices( - &bx, - constant.span, - constant.ty, - c, - ); - return OperandRef { - val: Immediate(llval), - layout: bx.layout_of(ty) - }; - } - } - } + helper.do_call(self, &mut bx, fn_ty, fn_ptr, &llargs, + destination.as_ref().map(|&(_, target)| (ret_dest, target)), + cleanup); + } +} - self.codegen_operand(&mut bx, arg) - }).collect(); +impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { + pub fn codegen_block( + &mut self, + bb: mir::BasicBlock, + ) { + let mut bx = self.build_block(bb); + let data = &self.mir[bb]; + debug!("codegen_block({:?}={:?})", bb, data); - let callee_ty = instance.as_ref().unwrap().ty(bx.tcx()); - bx.codegen_intrinsic_call(callee_ty, &fn_ty, &args, dest, - terminator.source_info.span); + for statement in &data.statements { + bx = self.codegen_statement(bx, statement); + } - if let ReturnDest::IndirectOperand(dst, _) = ret_dest { - self.store_return(&mut bx, ret_dest, &fn_ty.ret, dst.llval); - } + self.codegen_terminator(bx, bb, data.terminator()); + } - if let Some((_, target)) = *destination { - funclet_br(self, &mut bx, target); - } else { - bx.unreachable(); - } + fn codegen_terminator( + &mut self, + mut bx: Bx, + bb: mir::BasicBlock, + terminator: &mir::Terminator<'tcx> + ) { + debug!("codegen_terminator: {:?}", terminator); - return; - } + // Create the cleanup bundle, if needed. + let funclet_bb = self.cleanup_kinds[bb].funclet_bb(bb); + let helper = TerminatorCodegenHelper { + bb: &bb, terminator, funclet_bb + }; - // Split the rust-call tupled arguments off. - let (first_args, untuple) = if abi == Abi::RustCall && !args.is_empty() { - let (tup, args) = args.split_last().unwrap(); - (args, Some(tup)) - } else { - (&args[..], None) - }; + self.set_debug_loc(&mut bx, terminator.source_info); + match terminator.kind { + mir::TerminatorKind::Resume => { + self.codegen_resume_terminator(helper, bx) + } - 'make_args: for (i, arg) in first_args.iter().enumerate() { - let mut op = self.codegen_operand(&mut bx, arg); - - if let (0, Some(ty::InstanceDef::Virtual(_, idx))) = (i, def) { - if let Pair(..) = op.val { - // In the case of Rc, we need to explicitly pass a - // *mut RcBox with a Scalar (not ScalarPair) ABI. This is a hack - // that is understood elsewhere in the compiler as a method on - // `dyn Trait`. - // To get a `*mut RcBox`, we just keep unwrapping newtypes until - // we get a value of a built-in pointer type - 'descend_newtypes: while !op.layout.ty.is_unsafe_ptr() - && !op.layout.ty.is_region_ptr() - { - 'iter_fields: for i in 0..op.layout.fields.count() { - let field = op.extract_field(&mut bx, i); - if !field.layout.is_zst() { - // we found the one non-zero-sized field that is allowed - // now find *its* non-zero-sized field, or stop if it's a - // pointer - op = field; - continue 'descend_newtypes - } - } - - span_bug!(span, "receiver has no non-zero-sized fields {:?}", op); - } + mir::TerminatorKind::Abort => { + bx.abort(); + bx.unreachable(); + } - // now that we have `*dyn Trait` or `&dyn Trait`, split it up into its - // data pointer and vtable. Look up the method in the vtable, and pass - // the data pointer as the first argument - match op.val { - Pair(data_ptr, meta) => { - llfn = Some(meth::VirtualIndex::from_index(idx) - .get_fn(&mut bx, meta, &fn_ty)); - llargs.push(data_ptr); - continue 'make_args - } - other => bug!("expected a Pair, got {:?}", other) - } - } else if let Ref(data_ptr, Some(meta), _) = op.val { - // by-value dynamic dispatch - llfn = Some(meth::VirtualIndex::from_index(idx) - .get_fn(&mut bx, meta, &fn_ty)); - llargs.push(data_ptr); - continue; - } else { - span_bug!(span, "can't codegen a virtual call on {:?}", op); - } - } + mir::TerminatorKind::Goto { target } => { + helper.funclet_br(self, &mut bx, target); + } - // The callee needs to own the argument memory if we pass it - // by-ref, so make a local copy of non-immediate constants. - match (arg, op.val) { - (&mir::Operand::Copy(_), Ref(_, None, _)) | - (&mir::Operand::Constant(_), Ref(_, None, _)) => { - let tmp = PlaceRef::alloca(&mut bx, op.layout, "const"); - op.val.store(&mut bx, tmp); - op.val = Ref(tmp.llval, None, tmp.align); - } - _ => {} - } + mir::TerminatorKind::SwitchInt { + ref discr, switch_ty, ref values, ref targets + } => { + self.codegen_switchint_terminator(helper, bx, discr, switch_ty, + values, targets); + } - self.codegen_argument(&mut bx, op, &mut llargs, &fn_ty.args[i]); - } - if let Some(tup) = untuple { - self.codegen_arguments_untupled(&mut bx, tup, &mut llargs, - &fn_ty.args[first_args.len()..]) - } + mir::TerminatorKind::Return => { + self.codegen_return_terminator(bx); + } - let fn_ptr = match (llfn, instance) { - (Some(llfn), _) => llfn, - (None, Some(instance)) => bx.get_fn(instance), - _ => span_bug!(span, "no llfn for call"), - }; + mir::TerminatorKind::Unreachable => { + bx.unreachable(); + } - do_call(self, &mut bx, fn_ty, fn_ptr, &llargs, - destination.as_ref().map(|&(_, target)| (ret_dest, target)), - cleanup); + mir::TerminatorKind::Drop { ref location, target, unwind } => { + self.codegen_drop_terminator(helper, bx, location, target, unwind); + } + + mir::TerminatorKind::Assert { ref cond, expected, ref msg, target, cleanup } => { + self.codegen_assert_terminator(helper, bx, terminator, cond, + expected, msg, target, cleanup); + } + + mir::TerminatorKind::DropAndReplace { .. } => { + bug!("undesugared DropAndReplace in codegen: {:?}", terminator); + } + + mir::TerminatorKind::Call { + ref func, + ref args, + ref destination, + cleanup, + from_hir_call: _ + } => { + self.codegen_call_terminator(helper, bx, terminator, func, + args, destination, cleanup); } mir::TerminatorKind::GeneratorDrop | mir::TerminatorKind::Yield { .. } => bug!("generator ops in codegen"), diff --git a/src/librustc_codegen_ssa/mir/mod.rs b/src/librustc_codegen_ssa/mir/mod.rs index 203d84bff5bb3..dc77d4673cd2a 100644 --- a/src/librustc_codegen_ssa/mir/mod.rs +++ b/src/librustc_codegen_ssa/mir/mod.rs @@ -2,10 +2,10 @@ use libc::c_uint; use rustc::ty::{self, Ty, TypeFoldable, UpvarSubsts}; use rustc::ty::layout::{TyLayout, HasTyCtxt}; use rustc::mir::{self, Mir}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::session::config::DebugInfo; use rustc_mir::monomorphize::Instance; -use rustc_target::abi::call::{FnType, PassMode}; +use rustc_target::abi::call::{FnType, PassMode, IgnoreMode}; use crate::base; use crate::debuginfo::{self, VariableAccess, VariableKind, FunctionDebugContext}; use crate::traits::*; @@ -85,7 +85,11 @@ pub struct FunctionCx<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> { scopes: IndexVec>, /// If this function is being monomorphized, this contains the type substitutions used. - param_substs: &'tcx Substs<'tcx>, + param_substs: SubstsRef<'tcx>, + + /// If this function is a C-variadic function, this contains the `PlaceRef` of the + /// "spoofed" `VaList`. + va_list_ref: Option>, } impl<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { @@ -246,13 +250,18 @@ pub fn codegen_mir<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( assert!(!instance.substs.needs_infer()); instance.substs }, + va_list_ref: None, }; let memory_locals = analyze::non_ssa_locals(&fx); // Allocate variable and temp allocas fx.locals = { - let args = arg_local_refs(&mut bx, &fx, &fx.scopes, &memory_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, &fx.scopes, &memory_locals, &mut va_list_ref); + fx.va_list_ref = va_list_ref; let mut allocate_local = |local| { let decl = &mir.local_decls[local]; @@ -433,6 +442,7 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( debuginfo::MirDebugScope >, memory_locals: &BitSet, + va_list_ref: &mut Option>, ) -> Vec> { let mir = fx.mir; let tcx = fx.cx.tcx(); @@ -447,6 +457,15 @@ fn arg_local_refs<'a, 'tcx: 'a, 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]; @@ -510,9 +529,16 @@ fn arg_local_refs<'a, 'tcx: 'a, 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 => { + PassMode::Ignore(IgnoreMode::Zst) => { return local(OperandRef::new_zst(bx.cx(), arg.layout)); } + PassMode::Ignore(IgnoreMode::CVarArgs) => { + let backend_type = bx.cx().immediate_backend_type(arg.layout); + return local(OperandRef { + val: OperandValue::Immediate(bx.cx().const_undef(backend_type)), + layout: arg.layout, + }); + } PassMode::Direct(_) => { let llarg = bx.get_param(bx.llfn(), llarg_idx as c_uint); bx.set_value_name(llarg, &name); @@ -559,9 +585,35 @@ fn arg_local_refs<'a, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>>( indirect_operand.store(bx, tmp); tmp } else { - let tmp = PlaceRef::alloca(bx, arg.layout, &name); - bx.store_fn_arg(arg, &mut llarg_idx, tmp); - tmp + if fx.fn_ty.c_variadic && last_arg_idx.map(|idx| arg_index == idx).unwrap_or(false) { + let va_list_impl = match arg_decl.ty.ty_adt_def() { + Some(adt) => adt.non_enum_variant(), + None => bug!("`va_list` language item improperly constructed") + }; + match tcx.type_of(va_list_impl.fields[0].did).sty { + ty::Ref(_, ty, _) => { + // If the underlying structure the `VaList` contains is a structure, + // we need to allocate it (e.g., X86_64 on Linux). + let tmp = PlaceRef::alloca(bx, arg.layout, &name); + if let ty::Adt(..) = ty.sty { + let layout = bx.layout_of(ty); + // Create an unnamed allocation for the backing structure + // and store it in the the spoofed `VaList`. + let backing = PlaceRef::alloca(bx, layout, ""); + bx.store(backing.llval, tmp.llval, layout.align.abi); + } + // Call `va_start` on the spoofed `VaList`. + bx.va_start(tmp.llval); + *va_list_ref = Some(tmp); + tmp + } + _ => bug!("improperly constructed `va_list` lang item"), + } + } else { + let tmp = PlaceRef::alloca(bx, arg.layout, &name); + bx.store_fn_arg(arg, &mut llarg_idx, tmp); + tmp + } }; arg_scope.map(|scope| { // Is this a regular argument? diff --git a/src/librustc_codegen_ssa/traits/intrinsic.rs b/src/librustc_codegen_ssa/traits/intrinsic.rs index 3cd0c39d4139a..cd5278989778f 100644 --- a/src/librustc_codegen_ssa/traits/intrinsic.rs +++ b/src/librustc_codegen_ssa/traits/intrinsic.rs @@ -20,4 +20,10 @@ pub trait IntrinsicCallMethods<'tcx>: BackendTypes { fn abort(&mut self); fn assume(&mut self, val: Self::Value); fn expect(&mut self, cond: Self::Value, expected: bool) -> Self::Value; + /// Trait method used to inject `va_start` on the "spoofed" `VaList` in + /// Rust defined C-variadic functions. + fn va_start(&mut self, val: Self::Value) -> Self::Value; + /// Trait method used to inject `va_end` on the "spoofed" `VaList` before + /// Rust defined C-variadic functions return. + fn va_end(&mut self, val: Self::Value) -> Self::Value; } diff --git a/src/librustc_codegen_utils/symbol_names.rs b/src/librustc_codegen_utils/symbol_names.rs index 8d105853d92f1..f529cf30a62ea 100644 --- a/src/librustc_codegen_utils/symbol_names.rs +++ b/src/librustc_codegen_utils/symbol_names.rs @@ -94,7 +94,7 @@ use rustc::hir::map::definitions::DefPathData; use rustc::ich::NodeIdHashingMode; use rustc::ty::item_path::{self, ItemPathBuffer, RootMode}; use rustc::ty::query::Providers; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::record_time; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; @@ -134,7 +134,7 @@ fn get_symbol_hash<'a, 'tcx>( // values for generic type parameters, // if any. - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ) -> u64 { debug!( "get_symbol_hash(def_id={:?}, parameters={:?})", diff --git a/src/librustc_driver/pretty.rs b/src/librustc_driver/pretty.rs index 4caf2ec676f07..0698c15346ebc 100644 --- a/src/librustc_driver/pretty.rs +++ b/src/librustc_driver/pretty.rs @@ -420,13 +420,13 @@ impl<'hir> pprust_hir::PpAnn for IdentifiedAnnotation<'hir> { } pprust_hir::AnnNode::Block(blk) => { s.s.space()?; - s.synth_comment(format!("block node_id: {} hir local_id: {}", - blk.id, blk.hir_id.local_id.as_u32())) + s.synth_comment(format!("block hir_id: {} hir local_id: {}", + blk.hir_id, blk.hir_id.local_id.as_u32())) } pprust_hir::AnnNode::Expr(expr) => { s.s.space()?; - s.synth_comment(format!("node_id: {} hir local_id: {}", - expr.id, expr.hir_id.local_id.as_u32()))?; + s.synth_comment(format!("expr hir_id: {} hir local_id: {}", + expr.hir_id, expr.hir_id.local_id.as_u32()))?; s.pclose() } pprust_hir::AnnNode::Pat(pat) => { @@ -834,15 +834,15 @@ fn print_flowgraph<'a, 'tcx, W: Write>(variants: Vec, let body_id = match code { blocks::Code::Expr(expr) => { // Find the function this expression is from. - let mut node_id = expr.id; + let mut hir_id = expr.hir_id; loop { - let node = tcx.hir().get(node_id); + let node = tcx.hir().get_by_hir_id(hir_id); if let Some(n) = hir::map::blocks::FnLikeNode::from_node(node) { break n.body(); } - let parent = tcx.hir().get_parent_node(node_id); - assert_ne!(node_id, parent); - node_id = parent; + let parent = tcx.hir().get_parent_node_by_hir_id(hir_id); + assert_ne!(hir_id, parent); + hir_id = parent; } } blocks::Code::FnLike(fn_like) => fn_like.body(), diff --git a/src/librustc_lint/builtin.rs b/src/librustc_lint/builtin.rs index 40c9ef3f63cf5..ac10b6403bd13 100644 --- a/src/librustc_lint/builtin.rs +++ b/src/librustc_lint/builtin.rs @@ -200,7 +200,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonShorthandFieldPatterns { } if let PatKind::Binding(_, _, _, ident, None) = fieldpat.node.pat.node { if cx.tcx.find_field_index(ident, &variant) == - Some(cx.tcx.field_index(fieldpat.node.id, cx.tables)) { + Some(cx.tcx.field_index(fieldpat.node.hir_id, cx.tables)) { let mut err = cx.struct_span_lint(NON_SHORTHAND_FIELD_PATTERNS, fieldpat.span, &format!("the `{}:` in this pattern is redundant", ident)); diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index f03f84ba519d6..35489ab42e730 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -1,7 +1,7 @@ #![allow(non_snake_case)] use rustc::hir::Node; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, AdtKind, ParamEnv, Ty, TyCtxt}; use rustc::ty::layout::{self, IntegerExt, LayoutOf, VariantIdx}; use rustc::{lint, util}; @@ -46,12 +46,12 @@ declare_lint! { #[derive(Copy, Clone)] pub struct TypeLimits { /// Id of the last visited negated expression - negated_expr_id: ast::NodeId, + negated_expr_id: hir::HirId, } impl TypeLimits { pub fn new() -> TypeLimits { - TypeLimits { negated_expr_id: ast::DUMMY_NODE_ID } + TypeLimits { negated_expr_id: hir::DUMMY_HIR_ID } } } @@ -71,8 +71,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { match e.node { hir::ExprKind::Unary(hir::UnNeg, ref expr) => { // propagate negation, if the negation itself isn't negated - if self.negated_expr_id != e.id { - self.negated_expr_id = expr.id; + if self.negated_expr_id != e.hir_id { + self.negated_expr_id = expr.hir_id; } } hir::ExprKind::Binary(binop, ref l, ref r) => { @@ -95,7 +95,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { }; let (_, max) = int_ty_range(int_type); let max = max as u128; - let negative = self.negated_expr_id == e.id; + let negative = self.negated_expr_id == e.hir_id; // Detect literal value out of range [min, max] inclusive // avoiding use of -min to prevent overflow/panic @@ -136,8 +136,8 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { _ => bug!(), }; if lit_val < min || lit_val > max { - let parent_id = cx.tcx.hir().get_parent_node(e.id); - if let Node::Expr(parent_expr) = cx.tcx.hir().get(parent_id) { + let parent_id = cx.tcx.hir().get_parent_node_by_hir_id(e.hir_id); + if let Node::Expr(parent_expr) = cx.tcx.hir().get_by_hir_id(parent_id) { if let hir::ExprKind::Cast(..) = parent_expr.node { if let ty::Char = cx.tables.expr_ty(parent_expr).sty { let mut err = cx.struct_span_lint( @@ -445,7 +445,7 @@ enum FfiResult<'tcx> { /// FIXME: This duplicates code in codegen. fn is_repr_nullable_ptr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def: &'tcx ty::AdtDef, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> bool { if def.variants.len() == 2 { let data_idx; @@ -766,8 +766,15 @@ 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 `VaList` in the functions list + // of inputs. + &sig.inputs()[..sig.inputs().len() - 1] + } else { + &sig.inputs()[..] + }; - for (input_ty, input_hir) in sig.inputs().iter().zip(&decl.inputs) { + for (input_ty, input_hir) in inputs.iter().zip(&decl.inputs) { self.check_type_for_ffi_and_report_errors(input_hir.span, input_ty); } diff --git a/src/librustc_lint/unused.rs b/src/librustc_lint/unused.rs index 407e684293515..86b8b276eafe5 100644 --- a/src/librustc_lint/unused.rs +++ b/src/librustc_lint/unused.rs @@ -58,7 +58,9 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults { let t = cx.tables.expr_ty(&expr); let type_permits_lack_of_use = if t.is_unit() - || cx.tcx.is_ty_uninhabited_from(cx.tcx.hir().get_module_parent(expr.id), t) { + || cx.tcx.is_ty_uninhabited_from( + cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), t) + { true } else { match t.sty { diff --git a/src/librustc_metadata/encoder.rs b/src/librustc_metadata/encoder.rs index 7e325ecc76c0b..5fdc5899a721e 100644 --- a/src/librustc_metadata/encoder.rs +++ b/src/librustc_metadata/encoder.rs @@ -1279,7 +1279,7 @@ impl<'a, 'b: 'a, 'tcx: 'b> IsolatedEncoder<'a, 'b, 'tcx> { /// Serialize the text of exported macros fn encode_info_for_macro_def(&mut self, macro_def: &hir::MacroDef) -> Entry<'tcx> { use syntax::print::pprust; - let def_id = self.tcx.hir().local_def_id(macro_def.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(macro_def.hir_id); Entry { kind: EntryKind::MacroDef(self.lazy(&MacroDef { body: pprust::tts_to_string(¯o_def.body.trees().collect::>()), @@ -1680,7 +1680,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for EncodeVisitor<'a, 'b, 'tcx> { self.index.encode_info_for_ty(ty); } fn visit_macro_def(&mut self, macro_def: &'tcx hir::MacroDef) { - let def_id = self.index.tcx.hir().local_def_id(macro_def.id); + let def_id = self.index.tcx.hir().local_def_id_from_hir_id(macro_def.hir_id); self.index.record(def_id, IsolatedEncoder::encode_info_for_macro_def, macro_def); } } @@ -1702,13 +1702,13 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { match param.kind { hir::GenericParamKind::Lifetime { .. } => {} hir::GenericParamKind::Type { ref default, .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); let has_default = Untracked(default.is_some()); let encode_info = IsolatedEncoder::encode_info_for_ty_param; self.record(def_id, encode_info, (def_id, has_default)); } hir::GenericParamKind::Const { .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); let encode_info = IsolatedEncoder::encode_info_for_const_param; self.record(def_id, encode_info, def_id); } @@ -1729,7 +1729,7 @@ impl<'a, 'b, 'tcx> IndexBuilder<'a, 'b, 'tcx> { fn encode_info_for_expr(&mut self, expr: &hir::Expr) { match expr.node { hir::ExprKind::Closure(..) => { - let def_id = self.tcx.hir().local_def_id(expr.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); self.record(def_id, IsolatedEncoder::encode_info_for_closure, def_id); } _ => {} diff --git a/src/librustc_metadata/index_builder.rs b/src/librustc_metadata/index_builder.rs index 9aff1133ea920..3e2571fc0b39c 100644 --- a/src/librustc_metadata/index_builder.rs +++ b/src/librustc_metadata/index_builder.rs @@ -185,7 +185,7 @@ macro_rules! read_hir { ($t:ty) => { impl<'tcx> DepGraphRead for &'tcx $t { fn read(&self, tcx: TyCtxt<'_, '_, '_>) { - tcx.hir().read(self.id); + tcx.hir().read_by_hir_id(self.hir_id); } } } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 1e9dab5016f8d..1091646bdd5c6 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -301,7 +301,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( } let mut_span = tcx.sess.source_map().span_until_non_whitespace(span); - tcx.struct_span_lint_node( + tcx.struct_span_lint_hir( UNUSED_MUT, vsi[local_decl.source_info.scope].lint_root, span, diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index c02c2b4934cf4..9eb09b514741c 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -10,8 +10,8 @@ use rustc::mir::{BasicBlock, BasicBlockData, Location, Mir, Place, Rvalue}; use rustc::mir::{SourceInfo, Statement, Terminator}; use rustc::mir::UserTypeProjection; use rustc::ty::fold::TypeFoldable; -use rustc::ty::subst::Substs; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid}; +use rustc::ty::subst::SubstsRef; pub(super) fn generate_constraints<'cx, 'gcx, 'tcx>( infcx: &InferCtxt<'cx, 'gcx, 'tcx>, @@ -50,7 +50,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx /// We sometimes have `substs` within an rvalue, or within a /// call. Make them live at the location where they appear. - fn visit_substs(&mut self, substs: &&'tcx Substs<'tcx>, location: Location) { + fn visit_substs(&mut self, substs: &SubstsRef<'tcx>, location: Location) { self.add_regular_live_constraint(*substs, location); self.super_substs(substs); } 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 089640ab7024b..cc01f632e075c 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 @@ -6,7 +6,7 @@ use rustc::hir; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; use rustc::mir::Mir; -use rustc::ty::subst::{Substs, UnpackedKind}; +use rustc::ty::subst::{SubstsRef, UnpackedKind}; use rustc::ty::{self, RegionKind, RegionVid, Ty, TyCtxt}; use rustc::util::ppaux::RegionHighlightMode; use rustc_errors::DiagnosticBuilder; @@ -541,7 +541,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// types+hir to search through). fn match_adt_and_segment<'hir>( &self, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, needle_fr: RegionVid, last_segment: &'hir hir::PathSegment, counter: &mut usize, @@ -587,7 +587,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { /// `search_stack` the types+hir to search through. fn try_match_adt_and_generic_args<'hir>( &self, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, needle_fr: RegionVid, args: &'hir hir::GenericArgs, search_stack: &mut Vec<(Ty<'tcx>, &'hir hir::Ty)>, diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index cbeb5dc206ee6..785f810d94159 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -14,7 +14,7 @@ use rustc::mir::{ ClosureOutlivesRequirement, ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory, Local, Location, Mir, }; -use rustc::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable}; +use rustc::ty::{self, subst::SubstsRef, RegionVid, Ty, TyCtxt, TypeFoldable}; use rustc::util::common::{self, ErrorReported}; use rustc_data_structures::bit_set::BitSet; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; @@ -1359,7 +1359,7 @@ pub trait ClosureRegionRequirementsExt<'gcx, 'tcx> { tcx: TyCtxt<'_, 'gcx, 'tcx>, location: Location, closure_def_id: DefId, - closure_substs: &'tcx ty::subst::Substs<'tcx>, + closure_substs: SubstsRef<'tcx>, ) -> Vec>; fn subst_closure_mapping( @@ -1390,7 +1390,7 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi tcx: TyCtxt<'_, 'gcx, 'tcx>, location: Location, closure_def_id: DefId, - closure_substs: &'tcx ty::subst::Substs<'tcx>, + closure_substs: SubstsRef<'tcx>, ) -> Vec> { debug!( "apply_requirements(location={:?}, closure_def_id={:?}, closure_substs={:?})", diff --git a/src/librustc_mir/borrow_check/nll/renumber.rs b/src/librustc_mir/borrow_check/nll/renumber.rs index e6a974fd8cc94..eab9e0ae171ed 100644 --- a/src/librustc_mir/borrow_check/nll/renumber.rs +++ b/src/librustc_mir/borrow_check/nll/renumber.rs @@ -1,4 +1,4 @@ -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, Ty, TypeFoldable}; use rustc::mir::{Location, Mir}; use rustc::mir::visit::{MutVisitor, TyContext}; @@ -55,7 +55,7 @@ impl<'a, 'gcx, 'tcx> MutVisitor<'tcx> for NLLVisitor<'a, 'gcx, 'tcx> { debug!("visit_ty: ty={:?}", ty); } - fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, location: Location) { + fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, location: Location) { debug!("visit_substs(substs={:?}, location={:?})", substs, location); *substs = self.renumber_regions(&{ *substs }); 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 49f90eb90aaf0..df035aab54c9c 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -36,7 +36,7 @@ use rustc::traits::query::type_op::custom::CustomTypeOp; use rustc::traits::query::{Fallible, NoSolution}; use rustc::traits::{ObligationCause, PredicateObligations}; use rustc::ty::fold::TypeFoldable; -use rustc::ty::subst::{Subst, Substs, UnpackedKind, UserSubsts}; +use rustc::ty::subst::{Subst, SubstsRef, UnpackedKind, UserSubsts}; use rustc::ty::{ self, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind, UserType, CanonicalUserTypeAnnotation, UserTypeAnnotationIndex, @@ -1602,10 +1602,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { from_hir_call: bool, ) { debug!("check_call_inputs({:?}, {:?})", sig, args); - if args.len() < sig.inputs().len() || (args.len() > sig.inputs().len() && !sig.variadic) { + // Do not count the `VaList` 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) { span_mirbug!(self, term, "call to {:?} with wrong # of args", sig); } - for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() { + for (n, (fn_arg, op_arg)) in inputs.iter().zip(args).enumerate() { let op_arg_ty = op_arg.ty(mir, self.tcx()); let category = if from_hir_call { ConstraintCategory::CallArgument @@ -2261,7 +2268,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> { &mut self, tcx: TyCtxt<'a, 'gcx, 'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, location: Location, ) -> ty::InstantiatedPredicates<'tcx> { if let Some(closure_region_requirements) = tcx.mir_borrowck(def_id).closure_requirements { diff --git a/src/librustc_mir/borrow_check/nll/universal_regions.rs b/src/librustc_mir/borrow_check/nll/universal_regions.rs index a5bf158257700..4d9a3775b3123 100644 --- a/src/librustc_mir/borrow_check/nll/universal_regions.rs +++ b/src/librustc_mir/borrow_check/nll/universal_regions.rs @@ -17,7 +17,7 @@ use rustc::hir::def_id::DefId; use rustc::hir::{self, BodyOwnerKind, HirId}; use rustc::infer::{InferCtxt, NLLRegionVariableOrigin}; use rustc::ty::fold::TypeFoldable; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, ClosureSubsts, GeneratorSubsts, RegionVid, Ty, TyCtxt}; use rustc::util::nodemap::FxHashMap; use rustc_data_structures::indexed_vec::{Idx, IndexVec}; @@ -94,12 +94,12 @@ pub enum DefiningTy<'tcx> { /// The MIR is a fn item with the given `DefId` and substs. The signature /// of the function can be bound then with the `fn_sig` query. - FnDef(DefId, &'tcx Substs<'tcx>), + FnDef(DefId, SubstsRef<'tcx>), /// The MIR represents some form of constant. The signature then /// is that it has no inputs and a single return value, which is /// the value of the constant. - Const(DefId, &'tcx Substs<'tcx>), + Const(DefId, SubstsRef<'tcx>), } impl<'tcx> DefiningTy<'tcx> { @@ -138,7 +138,7 @@ struct UniversalRegionIndices<'tcx> { /// used because trait matching and type-checking will feed us /// region constraints that reference those regions and we need to /// be able to map them our internal `RegionVid`. This is - /// basically equivalent to a `Substs`, except that it also + /// basically equivalent to a `InternalSubsts`, except that it also /// contains an entry for `ReStatic` -- it might be nice to just /// use a substs, and then handle `ReStatic` another way. indices: FxHashMap, RegionVid>, @@ -222,7 +222,7 @@ impl<'tcx> UniversalRegions<'tcx> { /// `V[1]: V[2]`. pub fn closure_mapping( tcx: TyCtxt<'_, '_, 'tcx>, - closure_substs: &'tcx Substs<'tcx>, + closure_substs: SubstsRef<'tcx>, expected_num_vars: usize, closure_base_def_id: DefId, ) -> IndexVec> { @@ -507,7 +507,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { BodyOwnerKind::Const | BodyOwnerKind::Static(..) => { assert_eq!(closure_base_def_id, self.mir_def_id); - let identity_substs = Substs::identity_for_item(tcx, closure_base_def_id); + let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let substs = self.infcx .replace_free_regions_with_nll_infer_vars(FR, &identity_substs); DefiningTy::Const(self.mir_def_id, substs) @@ -527,7 +527,7 @@ impl<'cx, 'gcx, 'tcx> UniversalRegionsBuilder<'cx, 'gcx, 'tcx> { let tcx = self.infcx.tcx; let gcx = tcx.global_tcx(); let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id); - let identity_substs = Substs::identity_for_item(gcx, closure_base_def_id); + let identity_substs = InternalSubsts::identity_for_item(gcx, closure_base_def_id); let fr_substs = match defining_ty { DefiningTy::Closure(_, ClosureSubsts { ref substs }) | DefiningTy::Generator(_, GeneratorSubsts { ref substs }, _) => { diff --git a/src/librustc_mir/build/block.rs b/src/librustc_mir/build/block.rs index 627fd7d2e1667..cba5039122a76 100644 --- a/src/librustc_mir/build/block.rs +++ b/src/librustc_mir/build/block.rs @@ -204,14 +204,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { debug!("update_source_scope_for({:?}, {:?})", span, safety_mode); let new_unsafety = match safety_mode { BlockSafety::Safe => None, - BlockSafety::ExplicitUnsafe(node_id) => { + BlockSafety::ExplicitUnsafe(hir_id) => { assert_eq!(self.push_unsafe_count, 0); match self.unpushed_unsafe { Safety::Safe => {} _ => return } - self.unpushed_unsafe = Safety::ExplicitUnsafe(node_id); - Some(Safety::ExplicitUnsafe(node_id)) + self.unpushed_unsafe = Safety::ExplicitUnsafe(hir_id); + Some(Safety::ExplicitUnsafe(hir_id)) } BlockSafety::PushUnsafe => { self.push_unsafe_count += 1; diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 903c8f8657f3d..19507c900da64 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -12,7 +12,7 @@ use rustc::middle::region; use rustc::mir::*; use rustc::mir::visit::{MutVisitor, TyContext}; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::util::nodemap::NodeMap; use rustc_target::spec::PanicStrategy; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -72,13 +72,13 @@ pub fn mir_build<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Mir<'t }; tcx.infer_ctxt().enter(|infcx| { - let cx = Cx::new(&infcx, id); + let fn_hir_id = tcx.hir().node_to_hir_id(id); + let cx = Cx::new(&infcx, fn_hir_id); let mut mir = if cx.tables().tainted_by_errors { build::construct_error(cx, body_id) } else if cx.body_owner_kind.is_fn_or_closure() { // fetch the fully liberated fn signature (that is, all bound // types/lifetimes replaced) - let fn_hir_id = tcx.hir().node_to_hir_id(id); let fn_sig = cx.tables().liberated_fn_sigs()[fn_hir_id].clone(); let fn_def_id = tcx.hir().local_def_id(id); @@ -212,7 +212,7 @@ impl<'a, 'gcx: 'tcx, 'tcx> MutVisitor<'tcx> for GlobalizeMir<'a, 'gcx> { } } - fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) { + fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) { if let Some(lifted) = self.tcx.lift(substs) { *substs = lifted; } else { diff --git a/src/librustc_mir/build/scope.rs b/src/librustc_mir/build/scope.rs index 3392495f7a11b..71acf747d0856 100644 --- a/src/librustc_mir/build/scope.rs +++ b/src/librustc_mir/build/scope.rs @@ -308,17 +308,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { debug!("in_scope(region_scope={:?}, block={:?})", region_scope, block); let source_scope = self.source_scope; let tcx = self.hir.tcx(); - if let LintLevel::Explicit(node_id) = lint_level { + if let LintLevel::Explicit(current_hir_id) = lint_level { let same_lint_scopes = tcx.dep_graph.with_ignore(|| { let sets = tcx.lint_levels(LOCAL_CRATE); - let parent_hir_id = - tcx.hir().definitions().node_to_hir_id( - self.source_scope_local_data[source_scope].lint_root - ); - let current_hir_id = - tcx.hir().definitions().node_to_hir_id(node_id); - sets.lint_level_set(parent_hir_id) == - sets.lint_level_set(current_hir_id) + let parent_hir_id = self.source_scope_local_data[source_scope].lint_root; + sets.lint_level_set(parent_hir_id) == sets.lint_level_set(current_hir_id) }); if !same_lint_scopes { diff --git a/src/librustc_mir/const_eval.rs b/src/librustc_mir/const_eval.rs index 2f8e3189d12e9..35ca13891876c 100644 --- a/src/librustc_mir/const_eval.rs +++ b/src/librustc_mir/const_eval.rs @@ -665,11 +665,11 @@ pub fn const_eval_raw_provider<'a, 'tcx>( // because any code that existed before validation could not have failed validation // thus preventing such a hard error from being a backwards compatibility hazard Some(Def::Const(_)) | Some(Def::AssociatedConst(_)) => { - let node_id = tcx.hir().as_local_node_id(def_id).unwrap(); + let hir_id = tcx.hir().as_local_hir_id(def_id).unwrap(); err.report_as_lint( tcx.at(tcx.def_span(def_id)), "any use of this value will cause an error", - node_id, + hir_id, ) }, // promoting runtime code is only allowed to error if it references broken constants @@ -685,7 +685,7 @@ pub fn const_eval_raw_provider<'a, 'tcx>( err.report_as_lint( tcx.at(span), "reaching this expression at runtime will panic or abort", - tcx.hir().as_local_node_id(def_id).unwrap(), + tcx.hir().as_local_hir_id(def_id).unwrap(), ) } // anything else (array lengths, enum initializers, constant patterns) are reported diff --git a/src/librustc_mir/hair/cx/block.rs b/src/librustc_mir/hair/cx/block.rs index 4a64ddb73fc2e..f58e61915e8c9 100644 --- a/src/librustc_mir/hair/cx/block.rs +++ b/src/librustc_mir/hair/cx/block.rs @@ -30,7 +30,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Block { hir::BlockCheckMode::DefaultBlock => BlockSafety::Safe, hir::BlockCheckMode::UnsafeBlock(..) => - BlockSafety::ExplicitUnsafe(self.id), + BlockSafety::ExplicitUnsafe(self.hir_id), hir::BlockCheckMode::PushUnsafeBlock(..) => BlockSafety::PushUnsafe, hir::BlockCheckMode::PopUnsafeBlock(..) => @@ -103,7 +103,7 @@ fn mirror_stmts<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, }, pattern, initializer: local.init.to_ref(), - lint_level: cx.lint_level_of(local.id), + lint_level: cx.lint_level_of(local.hir_id), }, opt_destruction_scope: opt_dxn_ext, span: stmt_span, diff --git a/src/librustc_mir/hair/cx/expr.rs b/src/librustc_mir/hair/cx/expr.rs index 3c38f870b04b8..5548366db66ec 100644 --- a/src/librustc_mir/hair/cx/expr.rs +++ b/src/librustc_mir/hair/cx/expr.rs @@ -9,6 +9,7 @@ use rustc::mir::interpret::{GlobalId, ErrorHandled}; use rustc::ty::{self, AdtKind, Ty}; use rustc::ty::adjustment::{Adjustment, Adjust, AutoBorrow, AutoBorrowMutability}; use rustc::ty::cast::CastKind as TyCastKind; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::hir; use rustc::hir::def_id::LocalDefId; use rustc::mir::BorrowKind; @@ -24,7 +25,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { data: region::ScopeData::Node }; - debug!("Expr::make_mirror(): id={}, span={:?}", self.id, self.span); + debug!("Expr::make_mirror(): id={}, span={:?}", self.hir_id, self.span); let mut expr = make_mirror_unadjusted(cx, self); @@ -44,7 +45,7 @@ impl<'tcx> Mirror<'tcx> for &'tcx hir::Expr { kind: ExprKind::Scope { region_scope: expr_scope, value: expr.to_ref(), - lint_level: cx.lint_level_of(self.id), + lint_level: cx.lint_level_of(self.hir_id), }, }; @@ -529,7 +530,8 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty); } }; - let upvars = cx.tcx.with_freevars(expr.id, |freevars| { + let expr_node_id = cx.tcx.hir().hir_to_node_id(expr.hir_id); + let upvars = cx.tcx.with_freevars(expr_node_id, |freevars| { freevars.iter() .zip(substs.upvar_tys(def_id, cx.tcx)) .map(|(fv, ty)| capture_freevar(cx, expr, fv, ty)) @@ -559,7 +561,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, // Now comes the rote stuff: hir::ExprKind::Repeat(ref v, ref count) => { let def_id = cx.tcx.hir().local_def_id(count.id); - let substs = Substs::identity_for_item(cx.tcx.global_tcx(), def_id); + let substs = InternalSubsts::identity_for_item(cx.tcx.global_tcx(), def_id); let instance = ty::Instance::resolve( cx.tcx.global_tcx(), cx.param_env, @@ -637,7 +639,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, hir::ExprKind::Field(ref source, ..) => { ExprKind::Field { lhs: source.to_ref(), - name: Field::new(cx.tcx.field_index(expr.id, cx.tables)), + name: Field::new(cx.tcx.field_index(expr.hir_id, cx.tables)), } } hir::ExprKind::Cast(ref source, ref cast_ty) => { @@ -715,7 +717,7 @@ fn make_mirror_unadjusted<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, Some(did) => { // in case we are offsetting from a computed discriminant // and not the beginning of discriminants (which is always `0`) - let substs = Substs::identity_for_item(cx.tcx(), did); + let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(ty::LazyConst::Unevaluated(did, substs)); let bin = ExprKind::Binary { op: BinOp::Add, @@ -833,7 +835,7 @@ fn method_callee<'a, 'gcx, 'tcx>( cx: &mut Cx<'a, 'gcx, 'tcx>, expr: &hir::Expr, span: Span, - overloaded_callee: Option<(DefId, &'tcx Substs<'tcx>)>, + overloaded_callee: Option<(DefId, SubstsRef<'tcx>)>, ) -> Expr<'tcx> { let temp_lifetime = cx.region_scope_tree.temporary_scope(expr.hir_id.local_id); let (def_id, substs, user_ty) = match overloaded_callee { @@ -1132,7 +1134,7 @@ fn overloaded_place<'a, 'gcx, 'tcx>( cx: &mut Cx<'a, 'gcx, 'tcx>, expr: &'tcx hir::Expr, place_ty: Ty<'tcx>, - overloaded_callee: Option<(DefId, &'tcx Substs<'tcx>)>, + overloaded_callee: Option<(DefId, SubstsRef<'tcx>)>, args: Vec>, ) -> ExprKind<'tcx> { // For an overloaded *x or x[y] expression of type T, the method @@ -1184,7 +1186,7 @@ fn capture_freevar<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, let var_hir_id = cx.tcx.hir().node_to_hir_id(freevar.var_id()); let upvar_id = ty::UpvarId { var_path: ty::UpvarPath { hir_id: var_hir_id }, - closure_expr_id: cx.tcx.hir().local_def_id(closure_expr.id).to_local(), + closure_expr_id: cx.tcx.hir().local_def_id_from_hir_id(closure_expr.hir_id).to_local(), }; let upvar_capture = cx.tables().upvar_capture(upvar_id); let temp_lifetime = cx.region_scope_tree.temporary_scope(closure_expr.hir_id.local_id); @@ -1223,7 +1225,7 @@ fn field_refs<'a, 'gcx, 'tcx>(cx: &mut Cx<'a, 'gcx, 'tcx>, fields.iter() .map(|field| { FieldExprRef { - name: Field::new(cx.tcx.field_index(field.id, cx.tables)), + name: Field::new(cx.tcx.field_index(field.hir_id, cx.tables)), expr: field.expr.to_ref(), } }) diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index cd937d702fd77..70f04fb892866 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -12,7 +12,7 @@ use rustc::middle::region; use rustc::infer::InferCtxt; use rustc::ty::subst::Subst; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::ty::subst::{Kind, Substs}; +use rustc::ty::subst::{Kind, InternalSubsts}; use rustc::ty::layout::VariantIdx; use syntax::ast; use syntax::attr; @@ -26,11 +26,11 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { tcx: TyCtxt<'a, 'gcx, 'tcx>, infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - pub root_lint_level: ast::NodeId, + pub root_lint_level: hir::HirId, pub param_env: ty::ParamEnv<'gcx>, - /// Identity `Substs` for use with const-evaluation. - pub identity_substs: &'gcx Substs<'gcx>, + /// Identity `InternalSubsts` for use with const-evaluation. + pub identity_substs: &'gcx InternalSubsts<'gcx>, pub region_scope_tree: Lrc, pub tables: &'a ty::TypeckTables<'gcx>, @@ -51,10 +51,10 @@ pub struct Cx<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { pub fn new(infcx: &'a InferCtxt<'a, 'gcx, 'tcx>, - src_id: ast::NodeId) -> Cx<'a, 'gcx, 'tcx> { + src_id: hir::HirId) -> Cx<'a, 'gcx, 'tcx> { let tcx = infcx.tcx; - let src_def_id = tcx.hir().local_def_id(src_id); - let body_owner_kind = tcx.hir().body_owner_kind(src_id); + let src_def_id = tcx.hir().local_def_id_from_hir_id(src_id); + let body_owner_kind = tcx.hir().body_owner_kind_by_hir_id(src_id); let constness = match body_owner_kind { hir::BodyOwnerKind::Const | @@ -63,7 +63,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { hir::BodyOwnerKind::Fn => hir::Constness::NotConst, }; - let attrs = tcx.hir().attrs(src_id); + let attrs = tcx.hir().attrs_by_hir_id(src_id); // Some functions always have overflow checks enabled, // however, they may not get codegen'd, depending on @@ -82,7 +82,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { infcx, root_lint_level: lint_level, param_env: tcx.param_env(src_def_id), - identity_substs: Substs::identity_for_item(tcx.global_tcx(), src_def_id), + identity_substs: InternalSubsts::identity_for_item(tcx.global_tcx(), src_def_id), region_scope_tree: tcx.region_scope_tree(src_def_id), tables: tcx.typeck_tables_of(src_def_id), constness, @@ -197,14 +197,13 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { ty.needs_drop(self.tcx.global_tcx(), param_env) } - fn lint_level_of(&self, node_id: ast::NodeId) -> LintLevel { - let hir_id = self.tcx.hir().definitions().node_to_hir_id(node_id); + fn lint_level_of(&self, hir_id: hir::HirId) -> LintLevel { let has_lint_level = self.tcx.dep_graph.with_ignore(|| { self.tcx.lint_levels(LOCAL_CRATE).lint_level_set(hir_id).is_some() }); if has_lint_level { - LintLevel::Explicit(node_id) + LintLevel::Explicit(hir_id) } else { LintLevel::Inherited } @@ -237,7 +236,7 @@ impl UserAnnotatedTyHelpers<'gcx, 'tcx> for Cx<'_, 'gcx, 'tcx> { } } -fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: ast::NodeId) -> ast::NodeId { +fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: hir::HirId) -> hir::HirId { // Right now we insert a `with_ignore` node in the dep graph here to // ignore the fact that `lint_levels` below depends on the entire crate. // For now this'll prevent false positives of recompiling too much when @@ -249,11 +248,10 @@ fn lint_level_for_hir_id(tcx: TyCtxt<'_, '_, '_>, mut id: ast::NodeId) -> ast::N tcx.dep_graph.with_ignore(|| { let sets = tcx.lint_levels(LOCAL_CRATE); loop { - let hir_id = tcx.hir().definitions().node_to_hir_id(id); - if sets.lint_level_set(hir_id).is_some() { + if sets.lint_level_set(id).is_some() { return id } - let next = tcx.hir().get_parent_node(id); + let next = tcx.hir().get_parent_node_by_hir_id(id); if next == id { bug!("lint traversal reached the root of the crate"); } diff --git a/src/librustc_mir/hair/mod.rs b/src/librustc_mir/hair/mod.rs index bce0a0dd0a8bd..2efdacd7622c9 100644 --- a/src/librustc_mir/hair/mod.rs +++ b/src/librustc_mir/hair/mod.rs @@ -8,7 +8,7 @@ use rustc::mir::{BinOp, BorrowKind, Field, UnOp}; use rustc::hir::def_id::DefId; use rustc::infer::canonical::Canonical; use rustc::middle::region; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{AdtDef, UpvarSubsts, Ty, Const, LazyConst, UserType}; use rustc::ty::layout::VariantIdx; use rustc::hir; @@ -28,7 +28,7 @@ mod util; #[derive(Copy, Clone, Debug)] pub enum LintLevel { Inherited, - Explicit(ast::NodeId) + Explicit(hir::HirId) } impl LintLevel { @@ -54,7 +54,7 @@ pub struct Block<'tcx> { #[derive(Copy, Clone, Debug)] pub enum BlockSafety { Safe, - ExplicitUnsafe(ast::NodeId), + ExplicitUnsafe(hir::HirId), PushUnsafe, PopUnsafe } @@ -261,7 +261,7 @@ pub enum ExprKind<'tcx> { Adt { adt_def: &'tcx AdtDef, variant_index: VariantIdx, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, /// Optional user-given substs: for something like `let x = /// Bar:: { ... }`. diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index 10bef53e249c4..9e9a5d0f82ada 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -168,7 +168,7 @@ use super::{PatternFoldable, PatternFolder, compare_const_vals}; use rustc::hir::def_id::DefId; use rustc::hir::RangeEnd; -use rustc::ty::{self, Ty, TyCtxt, TypeFoldable, Const}; +use rustc::ty::{self, subst::SubstsRef, Ty, TyCtxt, TypeFoldable, Const}; use rustc::ty::layout::{Integer, IntegerExt, VariantIdx, Size}; use rustc::mir::Field; @@ -402,7 +402,7 @@ impl<'a, 'tcx> MatchCheckCtxt<'a, 'tcx> { fn is_variant_uninhabited(&self, variant: &'tcx ty::VariantDef, - substs: &'tcx ty::subst::Substs<'tcx>) + substs: SubstsRef<'tcx>) -> bool { if self.tcx.features().exhaustive_patterns { diff --git a/src/librustc_mir/hair/pattern/check_match.rs b/src/librustc_mir/hair/pattern/check_match.rs index 7c44d1bf2c936..9cecf4af7d44a 100644 --- a/src/librustc_mir/hair/pattern/check_match.rs +++ b/src/librustc_mir/hair/pattern/check_match.rs @@ -11,7 +11,7 @@ use rustc::middle::mem_categorization::cmt_; use rustc::middle::region; use rustc::session::Session; use rustc::ty::{self, Ty, TyCtxt}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::lint; use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc::util::common::ErrorReported; @@ -51,7 +51,7 @@ pub(crate) fn check_match<'a, 'tcx>( tables: tcx.body_tables(body_id), region_scope_tree: &tcx.region_scope_tree(def_id), param_env: tcx.param_env(def_id), - identity_substs: Substs::identity_for_item(tcx, def_id), + identity_substs: InternalSubsts::identity_for_item(tcx, def_id), }.visit_body(tcx.hir().body(body_id)); }) } @@ -64,7 +64,7 @@ struct MatchVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, tables: &'a ty::TypeckTables<'tcx>, param_env: ty::ParamEnv<'tcx>, - identity_substs: &'tcx Substs<'tcx>, + identity_substs: SubstsRef<'tcx>, region_scope_tree: &'a region::ScopeTree, } @@ -171,7 +171,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { } } - let module = self.tcx.hir().get_module_parent(scrut.id); + let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); MatchCheckCtxt::create_and_enter(self.tcx, self.param_env, module, |ref mut cx| { let mut have_errors = false; @@ -203,7 +203,7 @@ impl<'a, 'tcx> MatchVisitor<'a, 'tcx> { // Then, if the match has no arms, check whether the scrutinee // is uninhabited. let pat_ty = self.tables.node_type(scrut.hir_id); - let module = self.tcx.hir().get_module_parent(scrut.id); + let module = self.tcx.hir().get_module_parent_by_hir_id(scrut.hir_id); if inlined_arms.is_empty() { let scrutinee_is_uninhabited = if self.tcx.features().exhaustive_patterns { self.tcx.is_ty_uninhabited_from(module, pat_ty) @@ -561,10 +561,10 @@ struct MutationChecker<'a, 'tcx: 'a> { impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { fn matched_pat(&mut self, _: &Pat, _: &cmt_<'_>, _: euv::MatchMode) {} - fn consume(&mut self, _: ast::NodeId, _: Span, _: &cmt_<'_>, _: ConsumeMode) {} + fn consume(&mut self, _: hir::HirId, _: Span, _: &cmt_<'_>, _: ConsumeMode) {} fn consume_pat(&mut self, _: &Pat, _: &cmt_<'_>, _: ConsumeMode) {} fn borrow(&mut self, - _: ast::NodeId, + _: hir::HirId, span: Span, _: &cmt_<'_>, _: ty::Region<'tcx>, @@ -587,7 +587,7 @@ impl<'a, 'tcx> Delegate<'tcx> for MutationChecker<'a, 'tcx> { } } fn decl_without_init(&mut self, _: ast::NodeId, _: Span) {} - fn mutate(&mut self, _: ast::NodeId, span: Span, _: &cmt_<'_>, mode: MutateMode) { + fn mutate(&mut self, _: hir::HirId, span: Span, _: &cmt_<'_>, mode: MutateMode) { match mode { MutateMode::JustWrite | MutateMode::WriteAndRead => { struct_span_err!(self.cx.tcx.sess, span, E0302, "cannot assign in a pattern guard") diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index 4d571f4f78296..c234c2474ff1b 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -16,7 +16,7 @@ use rustc::mir::{UserTypeProjection}; use rustc::mir::interpret::{Scalar, GlobalId, ConstValue, sign_extend}; use rustc::ty::{self, Region, TyCtxt, AdtDef, Ty, Lift, UserType}; use rustc::ty::{CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations}; -use rustc::ty::subst::{Substs, Kind}; +use rustc::ty::subst::{SubstsRef, Kind}; use rustc::ty::layout::VariantIdx; use rustc::hir::{self, PatKind, RangeEnd}; use rustc::hir::def::{Def, CtorKind}; @@ -135,7 +135,7 @@ pub enum PatternKind<'tcx> { /// multiple variants. Variant { adt_def: &'tcx AdtDef, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, variant_index: VariantIdx, subpatterns: Vec>, }, @@ -330,13 +330,13 @@ pub struct PatternContext<'a, 'tcx: 'a> { pub tcx: TyCtxt<'a, 'tcx, 'tcx>, pub param_env: ty::ParamEnv<'tcx>, pub tables: &'a ty::TypeckTables<'tcx>, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, pub errors: Vec, } impl<'a, 'tcx> Pattern<'tcx> { pub fn from_hir(tcx: TyCtxt<'a, 'tcx, 'tcx>, - param_env_and_substs: ty::ParamEnvAnd<'tcx, &'tcx Substs<'tcx>>, + param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, tables: &'a ty::TypeckTables<'tcx>, pat: &'tcx hir::Pat) -> Self { let mut pcx = PatternContext::new(tcx, param_env_and_substs, tables); @@ -352,7 +352,7 @@ impl<'a, 'tcx> Pattern<'tcx> { impl<'a, 'tcx> PatternContext<'a, 'tcx> { pub fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, - param_env_and_substs: ty::ParamEnvAnd<'tcx, &'tcx Substs<'tcx>>, + param_env_and_substs: ty::ParamEnvAnd<'tcx, SubstsRef<'tcx>>, tables: &'a ty::TypeckTables<'tcx>) -> Self { PatternContext { tcx, @@ -631,7 +631,7 @@ impl<'a, 'tcx> PatternContext<'a, 'tcx> { fields.iter() .map(|field| { FieldPattern { - field: Field::new(self.tcx.field_index(field.node.id, + field: Field::new(self.tcx.field_index(field.node.hir_id, self.tables)), pattern: self.lower_pattern(&field.node.pat), } @@ -1093,7 +1093,7 @@ macro_rules! CloneImpls { CloneImpls!{ <'tcx> Span, Field, Mutability, ast::Name, ast::NodeId, usize, ty::Const<'tcx>, Region<'tcx>, Ty<'tcx>, BindingMode, &'tcx AdtDef, - &'tcx Substs<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>, + SubstsRef<'tcx>, &'tcx Kind<'tcx>, UserType<'tcx>, UserTypeProjection<'tcx>, PatternTypeProjection<'tcx> } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 0c1b5d65b8b68..8a32c3b636c71 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -9,7 +9,7 @@ use rustc::mir; use rustc::ty::layout::{ self, Size, Align, HasDataLayout, LayoutOf, TyLayout }; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, SubstsRef}; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::ty::query::TyCtxtAt; use rustc_data_structures::indexed_vec::IndexVec; @@ -244,7 +244,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc pub(super) fn resolve( &self, def_id: DefId, - substs: &'tcx Substs<'tcx> + substs: SubstsRef<'tcx> ) -> EvalResult<'tcx, ty::Instance<'tcx>> { trace!("resolve: {:?}, {:#?}", def_id, substs); trace!("param_env: {:#?}", self.param_env); @@ -306,7 +306,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc fn monomorphize_with_substs + Subst<'tcx>>( &self, t: T, - substs: &'tcx Substs<'tcx> + substs: SubstsRef<'tcx> ) -> T { // miri doesn't care about lifetimes, and will choke on some crazy ones // let's simply get rid of them diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index e0fee10cd008c..06e79dc4e7097 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -23,7 +23,6 @@ Rust MIR: a lowered representation of Rust. Also: an experiment! #![feature(unicode_internals)] #![feature(step_trait)] #![feature(slice_concat_ext)] -#![feature(try_from)] #![feature(reverse_bits)] #![feature(try_blocks)] diff --git a/src/librustc_mir/lints.rs b/src/librustc_mir/lints.rs index 6b6e8fcdc82cf..c795b412bfa93 100644 --- a/src/librustc_mir/lints.rs +++ b/src/librustc_mir/lints.rs @@ -5,7 +5,7 @@ use rustc::hir::map::blocks::FnLikeNode; use rustc::lint::builtin::UNCONDITIONAL_RECURSION; use rustc::mir::{self, Mir, TerminatorKind}; use rustc::ty::{AssociatedItem, AssociatedItemContainer, Instance, TyCtxt, TyKind}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::InternalSubsts; pub fn check(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &Mir<'tcx>, @@ -69,7 +69,7 @@ fn check_fn_for_unconditional_recursion(tcx: TyCtxt<'a, 'tcx, 'tcx>, }) => tcx.generics_of(trait_def_id).count(), _ => 0 }; - let caller_substs = &Substs::identity_for_item(tcx, def_id)[..trait_substs_count]; + let caller_substs = &InternalSubsts::identity_for_item(tcx, def_id)[..trait_substs_count]; while let Some(bb) = reachable_without_self_call_queue.pop() { if visited.contains(bb) { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index dd7158897b889..4cec306412e8b 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -180,7 +180,7 @@ use rustc::hir::itemlikevisit::ItemLikeVisitor; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::mir::interpret::{AllocId, ConstValue}; use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind}; use rustc::ty::adjustment::CustomCoerceUnsized; use rustc::session::config::EntryFnType; @@ -500,7 +500,7 @@ struct MirNeighborCollector<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &'a mir::Mir<'tcx>, output: &'a mut Vec>, - param_substs: &'tcx Substs<'tcx>, + param_substs: SubstsRef<'tcx>, } impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { @@ -748,7 +748,7 @@ fn should_monomorphize_locally<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: fn is_available_upstream_generic<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> bool { debug_assert!(!def_id.is_local()); @@ -956,7 +956,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> { debug!("RootCollector: ADT drop-glue for {}", def_id_to_string(self.tcx, def_id)); - let ty = Instance::new(def_id, Substs::empty()).ty(self.tcx); + let ty = Instance::new(def_id, InternalSubsts::empty()).ty(self.tcx); visit_drop_use(self.tcx, ty, true, self.output); } } @@ -1116,7 +1116,7 @@ fn create_mono_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, continue; } - let substs = Substs::for_item(tcx, method.def_id, |param, _| { + let substs = InternalSubsts::for_item(tcx, method.def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => tcx.types.re_erased.into(), GenericParamDefKind::Type {..} => { @@ -1218,7 +1218,7 @@ fn def_id_to_string<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn collect_lazy_const<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, constant: &ty::LazyConst<'tcx>, - param_substs: &'tcx Substs<'tcx>, + param_substs: SubstsRef<'tcx>, output: &mut Vec>, ) { let (def_id, substs) = match *constant { diff --git a/src/librustc_mir/monomorphize/item.rs b/src/librustc_mir/monomorphize/item.rs index 6e639c3a1179a..059af2dbba944 100644 --- a/src/librustc_mir/monomorphize/item.rs +++ b/src/librustc_mir/monomorphize/item.rs @@ -3,7 +3,7 @@ use rustc::hir; use rustc::hir::def_id::{DefId, LOCAL_CRATE}; use rustc::session::config::OptLevel; use rustc::ty::{self, Ty, TyCtxt, ClosureSubsts, GeneratorSubsts}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{SubstsRef, InternalSubsts}; use syntax::ast; use syntax::attr::InlineAttr; use std::fmt::{self, Write}; @@ -151,7 +151,7 @@ pub trait MonoItemExt<'a, 'tcx>: fmt::Debug { debug!("is_instantiable({:?})", self); let (def_id, substs) = match *self.as_mono_item() { MonoItem::Fn(ref instance) => (instance.def_id(), instance.substs), - MonoItem::Static(def_id) => (def_id, Substs::empty()), + MonoItem::Static(def_id) => (def_id, InternalSubsts::empty()), // global asm never has predicates MonoItem::GlobalAsm(..) => return true }; @@ -353,7 +353,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> { output.pop(); } - if sig.variadic { + if sig.c_variadic { if !sig.inputs().is_empty() { output.push_str(", ..."); } else { @@ -422,7 +422,7 @@ impl<'a, 'tcx> DefPathBasedNames<'a, 'tcx> { } fn push_type_params(&self, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, projections: I, output: &mut String, debug: bool) diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index d4145b8e47ea2..ce7c9af81cb07 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -4,7 +4,7 @@ use rustc::infer; use rustc::mir::*; use rustc::ty::{self, Ty, TyCtxt, GenericParamDefKind}; use rustc::ty::layout::VariantIdx; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::ty::query::Providers; use rustc_data_structures::indexed_vec::{IndexVec, Idx}; @@ -183,7 +183,7 @@ fn build_drop_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let substs = if let Some(ty) = ty { tcx.intern_substs(&[ty.into()]) } else { - Substs::identity_for_item(tcx, def_id) + InternalSubsts::identity_for_item(tcx, def_id) }; let sig = tcx.fn_sig(def_id).subst(tcx, substs); let sig = tcx.erase_late_bound_regions(&sig); @@ -451,7 +451,7 @@ impl<'a, 'tcx> CloneShimBuilder<'a, 'tcx> { ) { let tcx = self.tcx; - let substs = Substs::for_item(tcx, self.def_id, |param, _| { + let substs = InternalSubsts::for_item(tcx, self.def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => tcx.types.re_erased.into(), GenericParamDefKind::Type {..} => ty.into(), diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 66529e579835d..3ed63d749cd35 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -12,7 +12,6 @@ use rustc::lint::builtin::{SAFE_EXTERN_STATICS, SAFE_PACKED_BORROWS, UNUSED_UNSA use rustc::mir::*; use rustc::mir::visit::{PlaceContext, Visitor, MutatingUseContext}; -use syntax::ast; use syntax::symbol::Symbol; use std::ops::Bound; @@ -29,8 +28,8 @@ pub struct UnsafetyChecker<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, /// Mark an `unsafe` block as used, so we don't lint it. - used_unsafe: FxHashSet, - inherited_blocks: Vec<(ast::NodeId, bool)>, + used_unsafe: FxHashSet, + inherited_blocks: Vec<(hir::HirId, bool)>, } impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> { @@ -349,7 +348,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { fn register_violations(&mut self, violations: &[UnsafetyViolation], - unsafe_blocks: &[(ast::NodeId, bool)]) { + unsafe_blocks: &[(hir::HirId, bool)]) { let safety = self.source_scope_local_data[self.source_info.scope].safety; let within_unsafe = match safety { // `unsafe` blocks are required in safe code @@ -375,10 +374,10 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { } // `unsafe` function bodies allow unsafe without additional unsafe blocks Safety::BuiltinUnsafe | Safety::FnUnsafe => true, - Safety::ExplicitUnsafe(node_id) => { + Safety::ExplicitUnsafe(hir_id) => { // mark unsafe block as used if there are any unsafe operations inside if !violations.is_empty() { - self.used_unsafe.insert(node_id); + self.used_unsafe.insert(hir_id); } // only some unsafety is allowed in const fn if self.min_const_fn { @@ -405,8 +404,8 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { true } }; - self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(node_id, is_used)| { - (node_id, is_used && !within_unsafe) + self.inherited_blocks.extend(unsafe_blocks.iter().map(|&(hir_id, is_used)| { + (hir_id, is_used && !within_unsafe) })); } fn check_mut_borrowing_layout_constrained_field( @@ -467,8 +466,8 @@ pub(crate) fn provide(providers: &mut Providers<'_>) { } struct UnusedUnsafeVisitor<'a> { - used_unsafe: &'a FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>, + used_unsafe: &'a FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>, } impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { @@ -482,19 +481,19 @@ impl<'a, 'tcx> hir::intravisit::Visitor<'tcx> for UnusedUnsafeVisitor<'a> { hir::intravisit::walk_block(self, block); if let hir::UnsafeBlock(hir::UserProvided) = block.rules { - self.unsafe_blocks.push((block.id, self.used_unsafe.contains(&block.id))); + self.unsafe_blocks.push((block.hir_id, self.used_unsafe.contains(&block.hir_id))); } } } fn check_unused_unsafe<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - used_unsafe: &FxHashSet, - unsafe_blocks: &'a mut Vec<(ast::NodeId, bool)>) + used_unsafe: &FxHashSet, + unsafe_blocks: &'a mut Vec<(hir::HirId, bool)>) { let body_id = - tcx.hir().as_local_node_id(def_id).and_then(|node_id| { - tcx.hir().maybe_body_owned_by(node_id) + tcx.hir().as_local_hir_id(def_id).and_then(|hir_id| { + tcx.hir().maybe_body_owned_by_by_hir_id(hir_id) }); let body_id = match body_id { @@ -574,18 +573,18 @@ fn unsafe_derive_on_repr_packed<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: D &message); } -/// Returns the `NodeId` for an enclosing scope that is also `unsafe`. +/// Returns the `HirId` for an enclosing scope that is also `unsafe`. fn is_enclosed(tcx: TyCtxt<'_, '_, '_>, - used_unsafe: &FxHashSet, - id: ast::NodeId) -> Option<(String, ast::NodeId)> { - let parent_id = tcx.hir().get_parent_node(id); + used_unsafe: &FxHashSet, + id: hir::HirId) -> Option<(String, hir::HirId)> { + let parent_id = tcx.hir().get_parent_node_by_hir_id(id); if parent_id != id { if used_unsafe.contains(&parent_id) { Some(("block".to_string(), parent_id)) } else if let Some(Node::Item(&hir::Item { node: hir::ItemKind::Fn(_, header, _, _), .. - })) = tcx.hir().find(parent_id) { + })) = tcx.hir().find_by_hir_id(parent_id) { match header.unsafety { hir::Unsafety::Unsafe => Some(("fn".to_string(), parent_id)), hir::Unsafety::Normal => None, @@ -599,14 +598,14 @@ fn is_enclosed(tcx: TyCtxt<'_, '_, '_>, } fn report_unused_unsafe(tcx: TyCtxt<'_, '_, '_>, - used_unsafe: &FxHashSet, - id: ast::NodeId) { - let span = tcx.sess.source_map().def_span(tcx.hir().span(id)); + used_unsafe: &FxHashSet, + id: hir::HirId) { + let span = tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)); let msg = "unnecessary `unsafe` block"; - let mut db = tcx.struct_span_lint_node(UNUSED_UNSAFE, id, span, msg); + let mut db = tcx.struct_span_lint_hir(UNUSED_UNSAFE, id, span, msg); db.span_label(span, msg); if let Some((kind, id)) = is_enclosed(tcx, used_unsafe, id) { - db.span_label(tcx.sess.source_map().def_span(tcx.hir().span(id)), + db.span_label(tcx.sess.source_map().def_span(tcx.hir().span_by_hir_id(id)), format!("because it's nested under this `unsafe` {}", kind)); } db.emit(); @@ -655,20 +654,20 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { .note(&details.as_str()[..]) .emit(); } - UnsafetyViolationKind::ExternStatic(lint_node_id) => { + UnsafetyViolationKind::ExternStatic(lint_hir_id) => { tcx.lint_node_note(SAFE_EXTERN_STATICS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), &details.as_str()[..]); } - UnsafetyViolationKind::BorrowPacked(lint_node_id) => { + UnsafetyViolationKind::BorrowPacked(lint_hir_id) => { if let Some(impl_def_id) = builtin_derive_def_id(tcx, def_id) { tcx.unsafe_derive_on_repr_packed(impl_def_id); } else { tcx.lint_node_note(SAFE_PACKED_BORROWS, - lint_node_id, + lint_hir_id, source_info.span, &format!("{} is unsafe and requires unsafe function or block \ (error E0133)", &description.as_str()[..]), @@ -679,7 +678,7 @@ pub fn check_unsafety<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) { } let mut unsafe_blocks: Vec<_> = unsafe_blocks.into_iter().collect(); - unsafe_blocks.sort(); + unsafe_blocks.sort_by_cached_key(|(hir_id, _)| tcx.hir().hir_to_node_id(*hir_id)); let used_unsafe: FxHashSet<_> = unsafe_blocks.iter() .flat_map(|&&(id, used)| if used { Some(id) } else { None }) .collect(); diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 1acc7b6e0c57f..5ed0055e7c4f4 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -10,7 +10,7 @@ use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUs use rustc::mir::interpret::{EvalErrorKind, Scalar, GlobalId, EvalResult}; use rustc::ty::{TyCtxt, self, Instance}; use syntax::source_map::{Span, DUMMY_SP}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::InternalSubsts; use rustc_data_structures::indexed_vec::IndexVec; use rustc::ty::ParamEnv; use rustc::ty::layout::{ @@ -288,7 +288,7 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { // FIXME: can't handle code with generics return None; } - let substs = Substs::identity_for_item(self.tcx, self.source.def_id()); + let substs = InternalSubsts::identity_for_item(self.tcx, self.source.def_id()); let instance = Instance::new(self.source.def_id(), substs); let cid = GlobalId { instance, @@ -430,10 +430,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> { } else { "left" }; - let node_id = source_scope_local_data[source_info.scope].lint_root; - self.tcx.lint_node( + let hir_id = source_scope_local_data[source_info.scope].lint_root; + self.tcx.lint_hir( ::rustc::lint::builtin::EXCEEDING_BITSHIFTS, - node_id, + hir_id, span, &format!("attempt to shift {} with overflow", dir)); return None; diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index 84f209f8776d9..9494d4b1f6c39 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -4,7 +4,7 @@ //! N.B., we do _not_ erase regions of statements that are relevant for //! "types-as-contracts"-validation, namely, `AcquireValid` and `ReleaseValid`. -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt}; use rustc::mir::*; use rustc::mir::visit::{MutVisitor, TyContext}; @@ -36,7 +36,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> { *constant = self.tcx.erase_regions(constant); } - fn visit_substs(&mut self, substs: &mut &'tcx Substs<'tcx>, _: Location) { + fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) { *substs = self.tcx.erase_regions(substs); } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 0866b87cf17e6..09142828f18af 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -55,7 +55,7 @@ use rustc::mir::*; use rustc::mir::visit::{PlaceContext, Visitor, MutVisitor}; use rustc::ty::{self, TyCtxt, AdtDef, Ty}; use rustc::ty::layout::VariantIdx; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::bit_set::BitSet; @@ -154,7 +154,7 @@ struct SuspensionPoint { struct TransformVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, state_adt_ref: &'tcx AdtDef, - state_substs: &'tcx Substs<'tcx>, + state_substs: SubstsRef<'tcx>, // The index of the generator state in the generator struct state_field: usize, diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 07ebbf6d0ebe3..56e4926090eac 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -9,7 +9,7 @@ use rustc_data_structures::indexed_vec::{Idx, IndexVec}; use rustc::mir::*; use rustc::mir::visit::*; use rustc::ty::{self, Instance, InstanceDef, ParamEnv, Ty, TyCtxt}; -use rustc::ty::subst::{Subst,Substs}; +use rustc::ty::subst::{Subst, SubstsRef}; use std::collections::VecDeque; use std::iter; @@ -32,7 +32,7 @@ pub struct Inline; #[derive(Copy, Clone, Debug)] struct CallSite<'tcx> { callee: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, bb: BasicBlock, location: SourceInfo, } diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index e86ece138301f..cf3ba1765406c 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -5,7 +5,7 @@ use rustc::middle::lang_items; use rustc::traits::Reveal; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::layout::VariantIdx; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::util::IntTypeExt; use rustc_data_structures::indexed_vec::Idx; use crate::util::patch::MirPatch; @@ -189,7 +189,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> base_place: &Place<'tcx>, variant_path: D::Path, variant: &'tcx ty::VariantDef, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> Vec<(Place<'tcx>, Option)> { variant.fields.iter().enumerate().map(|(i, f)| { @@ -328,7 +328,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> self.drop_ladder(fields, succ, unwind).0 } - fn open_drop_for_box<'a>(&mut self, adt: &'tcx ty::AdtDef, substs: &'tcx Substs<'tcx>) + fn open_drop_for_box<'a>(&mut self, adt: &'tcx ty::AdtDef, substs: SubstsRef<'tcx>) -> BasicBlock { debug!("open_drop_for_box({:?}, {:?}, {:?})", self, adt, substs); @@ -346,7 +346,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> self.drop_subpath(&interior, interior_path, succ, unwind_succ) } - fn open_drop_for_adt<'a>(&mut self, adt: &'tcx ty::AdtDef, substs: &'tcx Substs<'tcx>) + fn open_drop_for_adt<'a>(&mut self, adt: &'tcx ty::AdtDef, substs: SubstsRef<'tcx>) -> BasicBlock { debug!("open_drop_for_adt({:?}, {:?}, {:?})", self, adt, substs); if adt.variants.len() == 0 { @@ -376,7 +376,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> } fn open_drop_for_adt_contents(&mut self, adt: &'tcx ty::AdtDef, - substs: &'tcx Substs<'tcx>) + substs: SubstsRef<'tcx>) -> (BasicBlock, Unwind) { let (succ, unwind) = self.drop_ladder_bottom(); if !adt.is_enum() { @@ -393,7 +393,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> } fn open_drop_for_multivariant(&mut self, adt: &'tcx ty::AdtDef, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, succ: BasicBlock, unwind: Unwind) -> (BasicBlock, Unwind) { @@ -867,7 +867,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> fn box_free_block<'a>( &mut self, adt: &'tcx ty::AdtDef, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, target: BasicBlock, unwind: Unwind, ) -> BasicBlock { @@ -878,7 +878,7 @@ impl<'l, 'b, 'tcx, D> DropCtxt<'l, 'b, 'tcx, D> fn unelaborated_free_block<'a>( &mut self, adt: &'tcx ty::AdtDef, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, target: BasicBlock, unwind: Unwind ) -> BasicBlock { diff --git a/src/librustc_passes/hir_stats.rs b/src/librustc_passes/hir_stats.rs index 4071b5902b030..c74314ce0c4b5 100644 --- a/src/librustc_passes/hir_stats.rs +++ b/src/librustc_passes/hir_stats.rs @@ -2,7 +2,7 @@ // pieces of AST and HIR. The resulting numbers are good approximations but not // completely accurate (some things might be counted twice, others missed). -use rustc::hir; +use rustc::hir::{self, HirId}; use rustc::hir::intravisit as hir_visit; use rustc::util::common::to_readable_str; use rustc::util::nodemap::{FxHashMap, FxHashSet}; @@ -12,7 +12,7 @@ use syntax_pos::Span; #[derive(Copy, Clone, PartialEq, Eq, Hash)] enum Id { - Node(NodeId), + Node(HirId), Attr(AttrId), None, } @@ -119,7 +119,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_item(&mut self, i: &'v hir::Item) { - self.record("Item", Id::Node(i.id), i); + self.record("Item", Id::Node(i.hir_id), i); hir_visit::walk_item(self, i) } @@ -129,22 +129,22 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_foreign_item(&mut self, i: &'v hir::ForeignItem) { - self.record("ForeignItem", Id::Node(i.id), i); + self.record("ForeignItem", Id::Node(i.hir_id), i); hir_visit::walk_foreign_item(self, i) } fn visit_local(&mut self, l: &'v hir::Local) { - self.record("Local", Id::Node(l.id), l); + self.record("Local", Id::Node(l.hir_id), l); hir_visit::walk_local(self, l) } fn visit_block(&mut self, b: &'v hir::Block) { - self.record("Block", Id::Node(b.id), b); + self.record("Block", Id::Node(b.hir_id), b); hir_visit::walk_block(self, b) } fn visit_stmt(&mut self, s: &'v hir::Stmt) { - self.record("Stmt", Id::Node(s.id), s); + self.record("Stmt", Id::Node(s.hir_id), s); hir_visit::walk_stmt(self, s) } @@ -154,17 +154,17 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_pat(&mut self, p: &'v hir::Pat) { - self.record("Pat", Id::Node(p.id), p); + self.record("Pat", Id::Node(p.hir_id), p); hir_visit::walk_pat(self, p) } fn visit_expr(&mut self, ex: &'v hir::Expr) { - self.record("Expr", Id::Node(ex.id), ex); + self.record("Expr", Id::Node(ex.hir_id), ex); hir_visit::walk_expr(self, ex) } fn visit_ty(&mut self, t: &'v hir::Ty) { - self.record("Ty", Id::Node(t.id), t); + self.record("Ty", Id::Node(t.hir_id), t); hir_visit::walk_ty(self, t) } @@ -184,12 +184,12 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_trait_item(&mut self, ti: &'v hir::TraitItem) { - self.record("TraitItem", Id::Node(ti.id), ti); + self.record("TraitItem", Id::Node(ti.hir_id), ti); hir_visit::walk_trait_item(self, ti) } fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) { - self.record("ImplItem", Id::Node(ii.id), ii); + self.record("ImplItem", Id::Node(ii.hir_id), ii); hir_visit::walk_impl_item(self, ii) } @@ -199,7 +199,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_struct_field(&mut self, s: &'v hir::StructField) { - self.record("StructField", Id::Node(s.id), s); + self.record("StructField", Id::Node(s.hir_id), s); hir_visit::walk_struct_field(self, s) } @@ -212,7 +212,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_lifetime(&mut self, lifetime: &'v hir::Lifetime) { - self.record("Lifetime", Id::Node(lifetime.id), lifetime); + self.record("Lifetime", Id::Node(lifetime.hir_id), lifetime); hir_visit::walk_lifetime(self, lifetime) } @@ -234,7 +234,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_assoc_type_binding(&mut self, type_binding: &'v hir::TypeBinding) { - self.record("TypeBinding", Id::Node(type_binding.id), type_binding); + self.record("TypeBinding", Id::Node(type_binding.hir_id), type_binding); hir_visit::walk_assoc_type_binding(self, type_binding) } @@ -243,7 +243,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { } fn visit_macro_def(&mut self, macro_def: &'v hir::MacroDef) { - self.record("MacroDef", Id::Node(macro_def.id), macro_def); + self.record("MacroDef", Id::Node(macro_def.hir_id), macro_def); hir_visit::walk_macro_def(self, macro_def) } } diff --git a/src/librustc_passes/rvalue_promotion.rs b/src/librustc_passes/rvalue_promotion.rs index 20f31b3ebc173..6b8e37b3b3133 100644 --- a/src/librustc_passes/rvalue_promotion.rs +++ b/src/librustc_passes/rvalue_promotion.rs @@ -22,8 +22,8 @@ use rustc::middle::mem_categorization as mc; use rustc::middle::mem_categorization::Categorization; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::query::Providers; -use rustc::ty::subst::Substs; -use rustc::util::nodemap::{ItemLocalSet, NodeSet}; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; +use rustc::util::nodemap::{ItemLocalSet, HirIdSet}; use rustc::hir; use rustc_data_structures::sync::Lrc; use syntax::ast; @@ -75,7 +75,7 @@ fn rvalue_promotable_map<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, in_static: false, mut_rvalue_borrows: Default::default(), param_env: ty::ParamEnv::empty(), - identity_substs: Substs::empty(), + identity_substs: InternalSubsts::empty(), result: ItemLocalSet::default(), }; @@ -92,9 +92,9 @@ struct CheckCrateVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, in_fn: bool, in_static: bool, - mut_rvalue_borrows: NodeSet, + mut_rvalue_borrows: HirIdSet, param_env: ty::ParamEnv<'tcx>, - identity_substs: &'tcx Substs<'tcx>, + identity_substs: SubstsRef<'tcx>, tables: &'a ty::TypeckTables<'tcx>, result: ItemLocalSet, } @@ -169,7 +169,7 @@ impl<'a, 'gcx> CheckCrateVisitor<'a, 'gcx> { fn remove_mut_rvalue_borrow(&mut self, pat: &hir::Pat) -> bool { let mut any_removed = false; pat.walk(|p| { - any_removed |= self.mut_rvalue_borrows.remove(&p.id); + any_removed |= self.mut_rvalue_borrows.remove(&p.hir_id); true }); any_removed @@ -199,7 +199,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { self.tables = self.tcx.typeck_tables_of(item_def_id); self.param_env = self.tcx.param_env(item_def_id); - self.identity_substs = Substs::identity_for_item(self.tcx, item_def_id); + self.identity_substs = InternalSubsts::identity_for_item(self.tcx, item_def_id); let body = self.tcx.hir().body(body_id); @@ -223,7 +223,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { hir::StmtKind::Local(ref local) => { if self.remove_mut_rvalue_borrow(&local.pat) { if let Some(init) = &local.init { - self.mut_rvalue_borrows.insert(init.id); + self.mut_rvalue_borrows.insert(init.hir_id); } } @@ -248,7 +248,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { outer &= check_adjustments(self, ex); // Handle borrows on (or inside the autorefs of) this expression. - if self.mut_rvalue_borrows.remove(&ex.id) { + if self.mut_rvalue_borrows.remove(&ex.hir_id) { outer = NotPromotable } @@ -318,7 +318,7 @@ fn check_expr_kind<'a, 'tcx>( } hir::ExprKind::Cast(ref from, _) => { let expr_promotability = v.check_expr(from); - debug!("Checking const cast(id={})", from.id); + debug!("Checking const cast(id={})", from.hir_id); match v.tables.cast_kinds().get(from.hir_id) { None => { v.tcx.sess.delay_span_bug(e.span, "no kind for cast"); @@ -456,9 +456,10 @@ fn check_expr_kind<'a, 'tcx>( hir::ExprKind::Closure(_capture_clause, ref _box_fn_decl, body_id, _span, _option_generator_movability) => { let nested_body_promotable = v.check_nested_body(body_id); + let node_id = v.tcx.hir().hir_to_node_id(e.hir_id); // Paths in constant contexts cannot refer to local variables, // as there are none, and thus closures can't have upvars there. - if v.tcx.with_freevars(e.id, |fv| !fv.is_empty()) { + if v.tcx.with_freevars(node_id, |fv| !fv.is_empty()) { NotPromotable } else { nested_body_promotable @@ -518,7 +519,7 @@ fn check_expr_kind<'a, 'tcx>( mut_borrow = v.remove_mut_rvalue_borrow(pat); } if mut_borrow { - v.mut_rvalue_borrows.insert(expr.id); + v.mut_rvalue_borrows.insert(expr.hir_id); } let _ = v.check_expr(expr); @@ -619,13 +620,13 @@ fn check_adjustments<'a, 'tcx>( impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> { fn consume(&mut self, - _consume_id: ast::NodeId, + _consume_id: hir::HirId, _consume_span: Span, _cmt: &mc::cmt_<'_>, _mode: euv::ConsumeMode) {} fn borrow(&mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, _borrow_span: Span, cmt: &mc::cmt_<'tcx>, _loan_region: ty::Region<'tcx>, @@ -678,7 +679,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for CheckCrateVisitor<'a, 'gcx> { fn decl_without_init(&mut self, _id: ast::NodeId, _span: Span) {} fn mutate(&mut self, - _assignment_id: ast::NodeId, + _assignment_id: hir::HirId, _assignment_span: Span, _assignee_cmt: &mc::cmt_<'_>, _mode: euv::MutateMode) { diff --git a/src/librustc_privacy/lib.rs b/src/librustc_privacy/lib.rs index 894cb4cf11b20..27103ab99651b 100644 --- a/src/librustc_privacy/lib.rs +++ b/src/librustc_privacy/lib.rs @@ -20,8 +20,8 @@ use rustc::middle::privacy::{AccessLevel, AccessLevels}; use rustc::ty::{self, TyCtxt, Ty, TraitRef, TypeFoldable, GenericParamDefKind}; use rustc::ty::fold::TypeVisitor; use rustc::ty::query::Providers; -use rustc::ty::subst::Substs; -use rustc::util::nodemap::NodeSet; +use rustc::ty::subst::InternalSubsts; +use rustc::util::nodemap::HirIdSet; use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::sync::Lrc; use syntax::ast::{self, DUMMY_NODE_ID, Ident}; @@ -127,7 +127,7 @@ impl<'a, 'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'a, 'tcx, V> { fn visit_ty(&mut self, ty: Ty<'tcx>) -> bool { let tcx = self.def_id_visitor.tcx(); - // Substs are not visited here because they are visited below in `super_visit_with`. + // InternalSubsts are not visited here because they are visited below in `super_visit_with`. match ty.sty { ty::Adt(&ty::AdtDef { did: def_id, .. }, ..) | ty::Foreign(def_id) | @@ -180,7 +180,7 @@ impl<'a, 'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'a, 'tcx, V> ty::ExistentialPredicate::Trait(trait_ref) => trait_ref, ty::ExistentialPredicate::Projection(proj) => proj.trait_ref(tcx), ty::ExistentialPredicate::AutoTrait(def_id) => - ty::ExistentialTraitRef { def_id, substs: Substs::empty() }, + ty::ExistentialTraitRef { def_id, substs: InternalSubsts::empty() }, }; let ty::ExistentialTraitRef { def_id, substs: _ } = trait_ref; if self.def_id_visitor.visit_def_id(def_id, "trait", &trait_ref) { @@ -271,7 +271,8 @@ fn def_id_visibility<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) return (ctor_vis, span, descr); } Node::Expr(expr) => { - return (ty::Visibility::Restricted(tcx.hir().get_module_parent(expr.id)), + return (ty::Visibility::Restricted( + tcx.hir().get_module_parent_by_hir_id(expr.hir_id)), expr.span, "private") } node => bug!("unexpected node kind: {:?}", node) @@ -695,18 +696,20 @@ impl<'a, 'tcx> Visitor<'tcx> for EmbargoVisitor<'a, 'tcx> { } fn visit_macro_def(&mut self, md: &'tcx hir::MacroDef) { + let node_id = self.tcx.hir().hir_to_node_id(md.hir_id); + if md.legacy { - self.update(md.id, Some(AccessLevel::Public)); + self.update(node_id, Some(AccessLevel::Public)); return } let module_did = ty::DefIdTree::parent( self.tcx, - self.tcx.hir().local_def_id(md.id) + self.tcx.hir().local_def_id_from_hir_id(md.hir_id) ).unwrap(); let mut module_id = self.tcx.hir().as_local_node_id(module_did).unwrap(); let level = if md.vis.node.is_pub() { self.get(module_id) } else { None }; - let level = self.update(md.id, level); + let level = self.update(node_id, level); if level.is_none() { return } @@ -870,7 +873,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { // unmentioned fields, just check them all. for (vf_index, variant_field) in variant.fields.iter().enumerate() { let field = fields.iter().find(|f| { - self.tcx.field_index(f.id, self.tables) == vf_index + self.tcx.field_index(f.hir_id, self.tables) == vf_index }); let (use_ctxt, span) = match field { Some(field) => (field.ident.span, field.span), @@ -881,7 +884,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { } else { for field in fields { let use_ctxt = field.ident.span; - let index = self.tcx.field_index(field.id, self.tables); + let index = self.tcx.field_index(field.hir_id, self.tables); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); } } @@ -900,7 +903,7 @@ impl<'a, 'tcx> Visitor<'tcx> for NamePrivacyVisitor<'a, 'tcx> { let variant = adt.variant_of_def(def); for field in fields { let use_ctxt = field.node.ident.span; - let index = self.tcx.field_index(field.node.id, self.tables); + let index = self.tcx.field_index(field.node.hir_id, self.tables); self.check_field(use_ctxt, field.span, adt, &variant.fields[index]); } } @@ -1152,7 +1155,7 @@ struct ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx: 'a> { access_levels: &'a AccessLevels, in_variant: bool, // Set of errors produced by this obsolete visitor. - old_error_set: NodeSet, + old_error_set: HirIdSet, } struct ObsoleteCheckTypeForPrivatenessVisitor<'a, 'b: 'a, 'tcx: 'b> { @@ -1196,7 +1199,7 @@ impl<'a, 'tcx> ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn check_generic_bound(&mut self, bound: &hir::GenericBound) { if let hir::GenericBound::Trait(ref trait_ref, _) = *bound { if self.path_is_private_type(&trait_ref.trait_ref.path) { - self.old_error_set.insert(trait_ref.trait_ref.ref_id); + self.old_error_set.insert(trait_ref.trait_ref.hir_ref_id); } } } @@ -1452,7 +1455,7 @@ impl<'a, 'tcx> Visitor<'tcx> for ObsoleteVisiblePrivateTypesVisitor<'a, 'tcx> { fn visit_ty(&mut self, t: &'tcx hir::Ty) { if let hir::TyKind::Path(hir::QPath::Resolved(_, ref path)) = t.node { if self.path_is_private_type(path) { - self.old_error_set.insert(t.id); + self.old_error_set.insert(t.hir_id); } } intravisit::walk_ty(self, t) @@ -1596,7 +1599,7 @@ impl<'a, 'tcx> DefIdVisitor<'a, 'tcx> for SearchInterfaceForPrivateItemsVisitor< struct PrivateItemsInPublicInterfacesVisitor<'a, 'tcx: 'a> { tcx: TyCtxt<'a, 'tcx, 'tcx>, has_pub_restricted: bool, - old_error_set: &'a NodeSet, + old_error_set: &'a HirIdSet, private_crates: FxHashSet } @@ -1608,7 +1611,7 @@ impl<'a, 'tcx> PrivateItemsInPublicInterfacesVisitor<'a, 'tcx> { // Slow path taken only if there any errors in the crate. for &id in self.old_error_set { // Walk up the nodes until we find `item_id` (or we hit a root). - let mut id = id; + let mut id = self.tcx.hir().hir_to_node_id(id); loop { if id == item_id { has_old_errors = true; diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 1a7744786d80e..ac572b652130c 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -863,7 +863,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Resolver<'a> { fn visit_generics(&mut self, generics: &'tcx Generics) { // For type parameter defaults, we have to ban access - // to following type parameters, as the Substs can only + // to following type parameters, as the InternalSubsts can only // provide previous type parameters as they're built. We // put all the parameters on the ban list and then remove // them one by one as they are processed and become available. diff --git a/src/librustc_save_analysis/dump_visitor.rs b/src/librustc_save_analysis/dump_visitor.rs index 187ebf0bc4304..b82aee7c96ad2 100644 --- a/src/librustc_save_analysis/dump_visitor.rs +++ b/src/librustc_save_analysis/dump_visitor.rs @@ -1517,7 +1517,8 @@ impl<'l, 'tcx: 'l, 'll, O: DumpOutput + 'll> Visitor<'l> for DumpVisitor<'l, 'tc return; } }; - let def = self.save_ctxt.get_path_def(hir_expr.id); + let node_id = self.save_ctxt.tcx.hir().hir_to_node_id(hir_expr.hir_id); + let def = self.save_ctxt.get_path_def(node_id); self.process_struct_lit(ex, path, fields, adt.variant_of_def(def), base) } ast::ExprKind::MethodCall(ref seg, ref args) => self.process_method_call(ex, seg, args), diff --git a/src/librustc_save_analysis/lib.rs b/src/librustc_save_analysis/lib.rs index 8ab9a8e8dda86..af3f54187b0c3 100644 --- a/src/librustc_save_analysis/lib.rs +++ b/src/librustc_save_analysis/lib.rs @@ -397,7 +397,7 @@ impl<'l, 'tcx: 'l> SaveContext<'l, 'tcx> { Some(Node::Item(item)) => match item.node { hir::ItemKind::Impl(.., ref ty, _) => { let mut qualname = String::from("<"); - qualname.push_str(&self.tcx.hir().node_to_pretty_string(ty.id)); + qualname.push_str(&self.tcx.hir().hir_to_pretty_string(ty.hir_id)); let trait_id = self.tcx.trait_id_of_impl(impl_id); let mut decl_id = None; diff --git a/src/librustc_save_analysis/sig.rs b/src/librustc_save_analysis/sig.rs index 50a335bf90877..222c43de3b7b1 100644 --- a/src/librustc_save_analysis/sig.rs +++ b/src/librustc_save_analysis/sig.rs @@ -190,6 +190,7 @@ impl Sig for ast::Ty { Ok(replace_text(nested, text)) } ast::TyKind::Never => Ok(text_sig("!".to_owned())), + ast::TyKind::CVarArgs => Ok(text_sig("...".to_owned())), ast::TyKind::Tup(ref ts) => { let mut text = "(".to_owned(); let mut defs = vec![]; diff --git a/src/librustc_target/abi/call/arm.rs b/src/librustc_target/abi/call/arm.rs index 52d7f3ac3dcbf..e3fee8e5700c1 100644 --- a/src/librustc_target/abi/call/arm.rs +++ b/src/librustc_target/abi/call/arm.rs @@ -99,7 +99,7 @@ pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) // `extern "aapcs"`, then we must use the VFP registers for homogeneous aggregates. let vfp = cx.target_spec().llvm_target.ends_with("hf") && fty.conv != Conv::ArmAapcs - && !fty.variadic; + && !fty.c_variadic; if !fty.ret.is_ignore() { classify_ret_ty(cx, &mut fty.ret, vfp); diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index 411eb192d902b..fbbd120f934be 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -23,10 +23,18 @@ 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 struct). - Ignore, + /// Ignore the argument (useful for empty structs and C-variadic args). + Ignore(IgnoreMode), /// Pass the argument directly. Direct(ArgAttributes), /// Pass a pair's elements directly in two arguments. @@ -481,7 +489,10 @@ impl<'a, Ty> ArgType<'a, Ty> { } pub fn is_ignore(&self) -> bool { - self.mode == PassMode::Ignore + match self.mode { + PassMode::Ignore(_) => true, + _ => false + } } } @@ -520,7 +531,7 @@ pub struct FnType<'a, Ty> { /// LLVM return type. pub ret: ArgType<'a, Ty>, - pub variadic: bool, + pub c_variadic: bool, pub conv: Conv, } diff --git a/src/librustc_target/abi/call/x86.rs b/src/librustc_target/abi/call/x86.rs index 2e809571ab18b..6ca3ce88bd6eb 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_traits/chalk_context/program_clauses.rs b/src/librustc_traits/chalk_context/program_clauses.rs index adfd26814db1e..3f88d0e08b46a 100644 --- a/src/librustc_traits/chalk_context/program_clauses.rs +++ b/src/librustc_traits/chalk_context/program_clauses.rs @@ -10,7 +10,7 @@ use rustc::traits::{ Environment, }; use rustc::ty; -use rustc::ty::subst::{Substs, Subst}; +use rustc::ty::subst::{InternalSubsts, Subst}; use rustc::hir; use rustc::hir::def_id::DefId; use rustc_target::spec::abi; @@ -105,7 +105,7 @@ fn assemble_builtin_sized_impls<'tcx>( let fn_ptr = generic_types::fn_ptr( tcx, fn_ptr.inputs_and_output.len(), - fn_ptr.variadic, + fn_ptr.c_variadic, fn_ptr.unsafety, fn_ptr.abi ); @@ -129,7 +129,7 @@ fn assemble_builtin_sized_impls<'tcx>( // Struct def ty::Adt(adt_def, _) => { - let substs = Substs::bound_vars_for_item(tcx, adt_def.did); + let substs = InternalSubsts::bound_vars_for_item(tcx, adt_def.did); let adt = tcx.mk_ty(ty::Adt(adt_def, substs)); let sized_constraint = adt_def.sized_constraint(tcx) .iter() @@ -190,11 +190,11 @@ fn wf_clause_for_raw_ptr<'tcx>( fn wf_clause_for_fn_ptr<'tcx>( tcx: ty::TyCtxt<'_, '_, 'tcx>, arity_and_output: usize, - variadic: bool, + c_variadic: bool, unsafety: hir::Unsafety, abi: abi::Abi ) -> Clauses<'tcx> { - let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, variadic, unsafety, abi); + let fn_ptr = generic_types::fn_ptr(tcx, arity_and_output, c_variadic, unsafety, abi); let wf_clause = ProgramClause { goal: DomainGoal::WellFormed(WellFormed::Ty(fn_ptr)), @@ -503,7 +503,7 @@ impl ChalkInferenceContext<'cx, 'gcx, 'tcx> { wf_clause_for_fn_ptr( self.infcx.tcx, fn_ptr.inputs_and_output.len(), - fn_ptr.variadic, + fn_ptr.c_variadic, fn_ptr.unsafety, fn_ptr.abi ) diff --git a/src/librustc_traits/dropck_outlives.rs b/src/librustc_traits/dropck_outlives.rs index 7185c4ce44640..49fcb7cd83355 100644 --- a/src/librustc_traits/dropck_outlives.rs +++ b/src/librustc_traits/dropck_outlives.rs @@ -4,7 +4,7 @@ use rustc::traits::query::dropck_outlives::{DropckOutlivesResult, DtorckConstrai use rustc::traits::query::{CanonicalTyGoal, NoSolution}; use rustc::traits::{TraitEngine, Normalized, ObligationCause, TraitEngineExt}; use rustc::ty::query::Providers; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::ty::{self, ParamEnvAnd, Ty, TyCtxt}; use rustc::util::nodemap::FxHashSet; use rustc_data_structures::sync::Lrc; @@ -291,7 +291,7 @@ crate fn adt_dtorck_constraint<'a, 'tcx>( if def.is_phantom_data() { // The first generic parameter here is guaranteed to be a type because it's // `PhantomData`. - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); assert_eq!(substs.len(), 1); let result = DtorckConstraint { outlives: vec![], diff --git a/src/librustc_traits/generic_types.rs b/src/librustc_traits/generic_types.rs index 03511e1d76d05..f2ce9631f35ab 100644 --- a/src/librustc_traits/generic_types.rs +++ b/src/librustc_traits/generic_types.rs @@ -1,7 +1,7 @@ //! Utilities for creating generic types with bound vars in place of parameter values. use rustc::ty::{self, Ty, TyCtxt}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::InternalSubsts; use rustc::hir; use rustc::hir::def_id::DefId; use rustc_target::spec::abi; @@ -24,7 +24,7 @@ crate fn raw_ptr(tcx: TyCtxt<'_, '_, 'tcx>, mutbl: hir::Mutability) -> Ty<'tcx> crate fn fn_ptr( tcx: ty::TyCtxt<'_, '_, 'tcx>, arity_and_output: usize, - variadic: bool, + c_variadic: bool, unsafety: hir::Unsafety, abi: abi::Abi ) -> Ty<'tcx> { @@ -37,7 +37,7 @@ crate fn fn_ptr( let fn_sig = ty::Binder::bind(ty::FnSig { inputs_and_output, - variadic, + c_variadic, unsafety, abi, }); @@ -64,17 +64,17 @@ crate fn ref_ty(tcx: ty::TyCtxt<'_, '_, 'tcx>, mutbl: hir::Mutability) -> Ty<'tc } crate fn fn_def(tcx: ty::TyCtxt<'_, '_, 'tcx>, def_id: DefId) -> Ty<'tcx> { - tcx.mk_ty(ty::FnDef(def_id, Substs::bound_vars_for_item(tcx, def_id))) + tcx.mk_ty(ty::FnDef(def_id, InternalSubsts::bound_vars_for_item(tcx, def_id))) } crate fn closure(tcx: ty::TyCtxt<'_, '_, 'tcx>, def_id: DefId) -> Ty<'tcx> { tcx.mk_closure(def_id, ty::ClosureSubsts { - substs: Substs::bound_vars_for_item(tcx, def_id), + substs: InternalSubsts::bound_vars_for_item(tcx, def_id), }) } crate fn generator(tcx: ty::TyCtxt<'_, '_, 'tcx>, def_id: DefId) -> Ty<'tcx> { tcx.mk_generator(def_id, ty::GeneratorSubsts { - substs: Substs::bound_vars_for_item(tcx, def_id), + substs: InternalSubsts::bound_vars_for_item(tcx, def_id), }, hir::GeneratorMovability::Movable) } diff --git a/src/librustc_traits/lowering/mod.rs b/src/librustc_traits/lowering/mod.rs index 908fdcfe7430f..d261b2382e7a6 100644 --- a/src/librustc_traits/lowering/mod.rs +++ b/src/librustc_traits/lowering/mod.rs @@ -18,7 +18,7 @@ use rustc::traits::{ }; use rustc::ty::query::Providers; use rustc::ty::{self, List, TyCtxt}; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts}; use syntax::ast; use std::iter; @@ -182,7 +182,7 @@ fn program_clauses_for_trait<'a, 'tcx>( // } // ``` - let bound_vars = Substs::bound_vars_for_item(tcx, def_id); + let bound_vars = InternalSubsts::bound_vars_for_item(tcx, def_id); // `Self: Trait` let trait_pred = ty::TraitPredicate { @@ -294,7 +294,7 @@ fn program_clauses_for_impl<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId // } // ``` - let bound_vars = Substs::bound_vars_for_item(tcx, def_id); + let bound_vars = InternalSubsts::bound_vars_for_item(tcx, def_id); let trait_ref = tcx.impl_trait_ref(def_id) .expect("not an impl") @@ -336,7 +336,7 @@ pub fn program_clauses_for_type_def<'a, 'tcx>( // } // ``` - let bound_vars = Substs::bound_vars_for_item(tcx, def_id); + let bound_vars = InternalSubsts::bound_vars_for_item(tcx, def_id); // `Ty<...>` let ty = tcx.type_of(def_id).subst(tcx, bound_vars); @@ -426,7 +426,7 @@ pub fn program_clauses_for_associated_type_def<'a, 'tcx>( _ => bug!("not an trait container"), }; - let trait_bound_vars = Substs::bound_vars_for_item(tcx, trait_id); + let trait_bound_vars = InternalSubsts::bound_vars_for_item(tcx, trait_id); let trait_ref = ty::TraitRef { def_id: trait_id, substs: trait_bound_vars, @@ -564,7 +564,7 @@ pub fn program_clauses_for_associated_type_value<'a, 'tcx>( _ => bug!("not an impl container"), }; - let impl_bound_vars = Substs::bound_vars_for_item(tcx, impl_id); + let impl_bound_vars = InternalSubsts::bound_vars_for_item(tcx, impl_id); // `A0 as Trait` let trait_ref = tcx.impl_trait_ref(impl_id) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 71368927a801d..b3694752204ca 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -14,11 +14,11 @@ use rustc::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, ToPredicate, TypeFoldable}; use rustc::ty::{GenericParamDef, GenericParamDefKind}; -use rustc::ty::subst::{Kind, Subst, Substs}; +use rustc::ty::subst::{Kind, Subst, InternalSubsts, SubstsRef}; use rustc::ty::wf::object_region_bounds; use rustc_data_structures::sync::Lrc; use rustc_target::spec::abi; -use crate::require_c_abi_if_variadic; +use crate::require_c_abi_if_c_variadic; use smallvec::SmallVec; use syntax::ast; use syntax::feature_gate::{GateIssue, emit_feature_err}; @@ -177,7 +177,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { span: Span, def_id: DefId, item_segment: &hir::PathSegment) - -> &'tcx Substs<'tcx> + -> SubstsRef<'tcx> { let (substs, assoc_bindings, _) = item_segment.with_generic_args(|generic_args| { self.create_substs_for_ast_path( @@ -304,8 +304,8 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { } else { let mut multispan = MultiSpan::from_span(span); multispan.push_span_label(span_late, note.to_string()); - tcx.lint_node(lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS, - args.args[0].id(), multispan, msg); + tcx.lint_hir(lint::builtin::LATE_BOUND_LIFETIME_ARGUMENTS, + args.args[0].id(), multispan, msg); return (false, None); } } @@ -436,7 +436,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs>, bool), provided_kind: impl Fn(&GenericParamDef, &GenericArg) -> Kind<'tcx>, inferred_kind: impl Fn(Option<&[Kind<'tcx>]>, &GenericParamDef, bool) -> Kind<'tcx>, - ) -> &'tcx Substs<'tcx> { + ) -> SubstsRef<'tcx> { // Collect the segments of the path; we need to substitute arguments // for parameters throughout the entire path (wherever there are // generic parameters). @@ -548,7 +548,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { generic_args: &hir::GenericArgs, infer_types: bool, self_ty: Option>) - -> (&'tcx Substs<'tcx>, Vec>, Option>) + -> (SubstsRef<'tcx>, Vec>, Option>) { // If the type is parameterized by this region, then replace this // region with the current anon region binding (in other words, @@ -760,7 +760,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { trait_def_id: DefId, self_ty: Ty<'tcx>, trait_segment: &hir::PathSegment, - ) -> (&'tcx Substs<'tcx>, Vec>, Option>) { + ) -> (SubstsRef<'tcx>, Vec>, Option>) { debug!("create_substs_for_ast_trait_ref(trait_segment={:?})", trait_segment); @@ -885,7 +885,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let msg = format!("associated type `{}` is private", binding.item_name); tcx.sess.span_err(binding.span, &msg); } - tcx.check_stability(assoc_ty.def_id, Some(ref_id), binding.span); + tcx.check_stability(assoc_ty.def_id, Some(hir_ref_id), binding.span); if !speculative { dup_bindings.entry(assoc_ty.def_id) @@ -1267,7 +1267,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { // parameter or `Self`. pub fn associated_path_to_ty( &self, - ref_id: ast::NodeId, + hir_ref_id: hir::HirId, span: Span, qself_ty: Ty<'tcx>, qself_def: Def, @@ -1292,7 +1292,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let def = Def::Variant(variant_def.did); if permit_variants { check_type_alias_enum_variants_enabled(tcx, span); - tcx.check_stability(variant_def.did, Some(ref_id), span); + tcx.check_stability(variant_def.did, Some(hir_ref_id), span); return (qself_ty, def); } else { variant_resolution = Some(def); @@ -1370,7 +1370,6 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { }; let trait_did = bound.def_id(); - let hir_ref_id = self.tcx().hir().node_to_hir_id(ref_id); let (assoc_ident, def_scope) = tcx.adjust_ident(assoc_ident, trait_did, hir_ref_id); let item = tcx.associated_items(trait_did).find(|i| { Namespace::from(i.kind) == Namespace::Type && @@ -1385,12 +1384,12 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let msg = format!("{} `{}` is private", def.kind_name(), assoc_ident); tcx.sess.span_err(span, &msg); } - tcx.check_stability(item.def_id, Some(ref_id), span); + tcx.check_stability(item.def_id, Some(hir_ref_id), span); if let Some(variant_def) = variant_resolution { - let mut err = tcx.struct_span_lint_node( + let mut err = tcx.struct_span_lint_hir( AMBIGUOUS_ASSOCIATED_ITEMS, - ref_id, + hir_ref_id, span, "ambiguous associated item", ); @@ -1742,7 +1741,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { /// internal notion of a type. pub fn ast_ty_to_ty(&self, ast_ty: &hir::Ty) -> Ty<'tcx> { debug!("ast_ty_to_ty(id={:?}, ast_ty={:?} ty_ty={:?})", - ast_ty.id, ast_ty, ast_ty.node); + ast_ty.hir_id, ast_ty, ast_ty.node); let tcx = self.tcx(); @@ -1769,7 +1768,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { tcx.mk_tup(fields.iter().map(|t| self.ast_ty_to_ty(&t))) } hir::TyKind::BareFn(ref bf) => { - require_c_abi_if_variadic(tcx, &bf.decl, bf.abi, ast_ty.span); + require_c_abi_if_c_variadic(tcx, &bf.decl, bf.abi, ast_ty.span); tcx.mk_fn_ptr(self.ty_of_fn(bf.unsafety, bf.abi, &bf.decl)) } hir::TyKind::TraitObject(ref bounds, ref lifetime) => { @@ -1795,11 +1794,11 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { } else { Def::Err }; - self.associated_path_to_ty(ast_ty.id, ast_ty.span, ty, def, segment, false).0 + self.associated_path_to_ty(ast_ty.hir_id, ast_ty.span, ty, def, segment, false).0 } hir::TyKind::Array(ref ty, ref length) => { let length_def_id = tcx.hir().local_def_id(length.id); - let substs = Substs::identity_for_item(tcx, length_def_id); + let substs = InternalSubsts::identity_for_item(tcx, length_def_id); let length = ty::LazyConst::Unevaluated(length_def_id, substs); let length = tcx.mk_lazy_const(length); let array_ty = tcx.mk_ty(ty::Array(self.ast_ty_to_ty(&ty), length)); @@ -1823,6 +1822,15 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { hir::TyKind::Err => { tcx.types.err } + 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()]) + } }; self.record_ty(ast_ty.hir_id, result_ty, ast_ty.span); @@ -1840,7 +1848,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let generics = tcx.generics_of(def_id); debug!("impl_trait_ty_to_ty: generics={:?}", generics); - let substs = Substs::for_item(tcx, def_id, |param, _| { + let substs = InternalSubsts::for_item(tcx, def_id, |param, _| { if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) { // Our own parameters are the resolved lifetimes. match param.kind { @@ -1905,7 +1913,7 @@ impl<'o, 'gcx: 'tcx, 'tcx> dyn AstConv<'gcx, 'tcx> + 'o { let bare_fn_ty = ty::Binder::bind(tcx.mk_fn_sig( input_tys, output_ty, - decl.variadic, + decl.c_variadic, unsafety, abi )); diff --git a/src/librustc_typeck/check/_match.rs b/src/librustc_typeck/check/_match.rs index 13469f1696631..100e55fc36723 100644 --- a/src/librustc_typeck/check/_match.rs +++ b/src/librustc_typeck/check/_match.rs @@ -64,7 +64,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } PatKind::Path(ref qpath) => { - let (def, _, _) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, _, _) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); match def { Def::Const(..) | Def::AssociatedConst(..) => false, _ => true, @@ -630,7 +630,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); if self.diverges.get().always() { for arm in arms { - self.warn_if_unreachable(arm.body.id, arm.body.span, "arm"); + self.warn_if_unreachable(arm.body.hir_id, arm.body.span, "arm"); } } @@ -725,7 +725,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let cause = if i == 0 { // The reason for the first arm to fail is not that the match arms diverge, // but rather that there's a prior obligation that doesn't hold. - self.cause(arm_span, ObligationCauseCode::BlockTailExpression(arm.body.id)) + self.cause(arm_span, ObligationCauseCode::BlockTailExpression(arm.body.hir_id)) } else { self.cause(expr.span, ObligationCauseCode::MatchExpressionArm { arm_span, @@ -761,7 +761,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); ) -> Ty<'tcx> { // Resolve the path and check the definition for errors. - let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.id) { + let (variant, pat_ty) = if let Some(variant_ty) = self.check_struct_path(qpath, pat.hir_id) + { variant_ty } else { for field in fields { @@ -779,7 +780,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); self.demand_eqtype_pat(pat.span, expected, pat_ty, match_discrim_span); // Type-check subpatterns. - if self.check_struct_pat_fields(pat_ty, pat.id, pat.span, variant, fields, etc, def_bm) { + if self.check_struct_pat_fields(pat_ty, pat.hir_id, pat.span, variant, fields, etc, def_bm) + { pat_ty } else { self.tcx.types.err @@ -795,7 +797,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let tcx = self.tcx; // Resolve the path and check the definition for errors. - let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); match def { Def::Err => { self.set_tainted_by_errors(); @@ -818,7 +820,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } // Type-check the path. - let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id).0; + let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.hir_id).0; self.demand_suptype(pat.span, expected, pat_ty); pat_ty } @@ -849,7 +851,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); }; // Resolve the path and check the definition for errors. - let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.id, pat.span); + let (def, opt_ty, segments) = self.resolve_ty_and_def_ufcs(qpath, pat.hir_id, pat.span); if def == Def::Err { self.set_tainted_by_errors(); on_error(); @@ -857,7 +859,8 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); } // Type-check the path. - let (pat_ty, def) = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id); + let (pat_ty, def) = self.instantiate_value_path(segments, opt_ty, def, pat.span, + pat.hir_id); if !pat_ty.is_fn() { report_unexpected_def(def); return self.tcx.types.err; @@ -897,7 +900,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); let field_ty = self.field_ty(subpat.span, &variant.fields[i], substs); self.check_pat_walk(&subpat, field_ty, def_bm, match_arm_pat_span); - self.tcx.check_stability(variant.fields[i].did, Some(pat.id), subpat.span); + self.tcx.check_stability(variant.fields[i].did, Some(pat.hir_id), subpat.span); } } else { let subpats_ending = if subpats.len() == 1 { "" } else { "s" }; @@ -917,7 +920,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); fn check_struct_pat_fields(&self, adt_ty: Ty<'tcx>, - pat_id: ast::NodeId, + pat_id: hir::HirId, span: Span, variant: &'tcx ty::VariantDef, fields: &'gcx [Spanned], @@ -963,7 +966,7 @@ https://doc.rust-lang.org/reference/types.html#trait-objects"); vacant.insert(span); field_map.get(&ident) .map(|(i, f)| { - self.write_field_index(field.id, *i); + self.write_field_index(field.hir_id, *i); self.tcx.check_stability(f.did, Some(pat_id), span); self.field_ty(span, f, substs) }) diff --git a/src/librustc_typeck/check/callee.rs b/src/librustc_typeck/check/callee.rs index 84d3c203afbe4..0a4c0eb3aff72 100644 --- a/src/librustc_typeck/check/callee.rs +++ b/src/librustc_typeck/check/callee.rs @@ -250,7 +250,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let &ty::Adt(adt_def, ..) = t { if adt_def.is_enum() { if let hir::ExprKind::Call(ref expr, _) = call_expr.node { - unit_variant = Some(self.tcx.hir().node_to_pretty_string(expr.id)) + unit_variant = Some(self.tcx.hir().hir_to_pretty_string(expr.hir_id)) } } } @@ -368,20 +368,30 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, '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(), - fn_sig.inputs(), + inputs, ); self.check_argument_types( call_expr.span, call_expr.span, - fn_sig.inputs(), + inputs, &expected_arg_tys[..], arg_exprs, - fn_sig.variadic, + fn_sig.c_variadic, TupleArgumentsFlag::DontTupleArguments, def_span, ); @@ -414,7 +424,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn_sig.inputs(), &expected_arg_tys, arg_exprs, - fn_sig.variadic, + fn_sig.c_variadic, TupleArgumentsFlag::TupleArguments, None, ); diff --git a/src/librustc_typeck/check/cast.rs b/src/librustc_typeck/check/cast.rs index 317d6bbd78592..87276b8c66ca4 100644 --- a/src/librustc_typeck/check/cast.rs +++ b/src/librustc_typeck/check/cast.rs @@ -37,9 +37,9 @@ use rustc::hir; use rustc::session::Session; use rustc::traits; use rustc::ty::{self, Ty, TypeFoldable, TypeAndMut}; +use rustc::ty::subst::SubstsRef; use rustc::ty::adjustment::AllowTwoPhase; use rustc::ty::cast::{CastKind, CastTy}; -use rustc::ty::subst::Substs; use rustc::middle::lang_items; use syntax::ast; use syntax_pos::Span; @@ -69,7 +69,7 @@ enum PointerKind<'tcx> { /// The unsize info of this projection OfProjection(&'tcx ty::ProjectionTy<'tcx>), /// The unsize info of this opaque ty - OfOpaque(DefId, &'tcx Substs<'tcx>), + OfOpaque(DefId, SubstsRef<'tcx>), /// The unsize info of this parameter OfParam(&'tcx ty::ParamTy), } @@ -399,9 +399,9 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { } else { ("", lint::builtin::TRIVIAL_CASTS) }; - let mut err = fcx.tcx.struct_span_lint_node( + let mut err = fcx.tcx.struct_span_lint_hir( lint, - self.expr.id, + self.expr.hir_id, self.span, &format!("trivial {}cast: `{}` as `{}`", adjective, @@ -417,7 +417,7 @@ impl<'a, 'gcx, 'tcx> CastCheck<'tcx> { self.cast_ty = fcx.structurally_resolved_type(self.span, self.cast_ty); debug!("check_cast({}, {:?} as {:?})", - self.expr.id, + self.expr.hir_id, self.expr_ty, self.cast_ty); diff --git a/src/librustc_typeck/check/closure.rs b/src/librustc_typeck/check/closure.rs index 5f76524518390..db89b32be7b68 100644 --- a/src/librustc_typeck/check/closure.rs +++ b/src/librustc_typeck/check/closure.rs @@ -12,7 +12,7 @@ use rustc::traits::Obligation; use rustc::traits::error_reporting::ArgKind; use rustc::ty::{self, Ty, GenericParamDefKind}; use rustc::ty::fold::TypeFoldable; -use rustc::ty::subst::Substs; +use rustc::ty::subst::InternalSubsts; use std::cmp; use std::iter; use rustc_target::spec::abi::Abi; @@ -72,7 +72,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { opt_kind, expected_sig ); - let expr_def_id = self.tcx.hir().local_def_id(expr.id); + let expr_def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); let ClosureSignatures { bound_sig, @@ -86,7 +86,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.param_env, liberated_sig, decl, - expr.id, + expr.hir_id, body, gen, ).1; @@ -95,7 +95,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // types of upvars. These will be unified during the upvar // inference phase (`upvar.rs`). let base_substs = - Substs::identity_for_item(self.tcx, self.tcx.closure_base_def_id(expr_def_id)); + InternalSubsts::identity_for_item(self.tcx, self.tcx.closure_base_def_id(expr_def_id)); let substs = base_substs.extend_to(self.tcx,expr_def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => { @@ -131,8 +131,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let closure_type = self.tcx.mk_closure(expr_def_id, substs); debug!( - "check_closure: expr.id={:?} closure_type={:?}", - expr.id, closure_type + "check_closure: expr.hir_id={:?} closure_type={:?}", + expr.hir_id, closure_type ); // Tuple up the arguments and insert the resulting function type into @@ -141,7 +141,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.tcx.mk_fn_sig( iter::once(self.tcx.intern_tup(sig.inputs())), sig.output(), - sig.variadic, + sig.c_variadic, sig.unsafety, sig.abi, ) @@ -386,7 +386,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Watch out for some surprises and just ignore the // expectation if things don't see to match up with what we // expect. - if expected_sig.sig.variadic != decl.variadic { + if expected_sig.sig.c_variadic != decl.c_variadic { return self.sig_of_closure_no_expectation(expr_def_id, decl, body); } else if expected_sig.sig.inputs_and_output.len() != decl.inputs.len() + 1 { return self.sig_of_closure_with_mismatched_number_of_arguments( @@ -404,7 +404,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let bound_sig = ty::Binder::bind(self.tcx.mk_fn_sig( expected_sig.sig.inputs().iter().cloned(), expected_sig.sig.output(), - decl.variadic, + decl.c_variadic, hir::Unsafety::Normal, Abi::RustCall, )); @@ -586,7 +586,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let result = ty::Binder::bind(self.tcx.mk_fn_sig( supplied_arguments, supplied_return, - decl.variadic, + decl.c_variadic, hir::Unsafety::Normal, Abi::RustCall, )); @@ -621,7 +621,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let result = ty::Binder::bind(self.tcx.mk_fn_sig( supplied_arguments, self.tcx.types.err, - decl.variadic, + decl.c_variadic, hir::Unsafety::Normal, Abi::RustCall, )); diff --git a/src/librustc_typeck/check/coercion.rs b/src/librustc_typeck/check/coercion.rs index 8841f6b268419..64f61d5e5232e 100644 --- a/src/librustc_typeck/check/coercion.rs +++ b/src/librustc_typeck/check/coercion.rs @@ -823,7 +823,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!("coercion::try_find_coercion_lub({:?}, {:?})", prev_ty, new_ty); // Special-case that coercion alone cannot handle: - // Two function item types of differing IDs or Substs. + // Two function item types of differing IDs or InternalSubsts. if let (&ty::FnDef(..), &ty::FnDef(..)) = (&prev_ty.sty, &new_ty.sty) { // Don't reify if the function types have a LUB, i.e., they // are the same function and their parameters have a LUB. @@ -1177,7 +1177,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> Expressions::UpFront(coercion_sites) => { // if the user gave us an array to validate, check that we got // the next expression in the list, as expected - assert_eq!(coercion_sites[self.pushed].as_coercion_site().id, e.id); + assert_eq!(coercion_sites[self.pushed].as_coercion_site().hir_id, + e.hir_id); } } self.pushed += 1; @@ -1208,7 +1209,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> db.span_label(cause.span, "return type is not `()`"); } ObligationCauseCode::BlockTailExpression(blk_id) => { - let parent_id = fcx.tcx.hir().get_parent_node(blk_id); + let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(blk_id); db = self.report_return_mismatched_types( cause, expected, @@ -1246,8 +1247,8 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> found: Ty<'tcx>, err: TypeError<'tcx>, fcx: &FnCtxt<'a, 'gcx, 'tcx>, - id: syntax::ast::NodeId, - expression: Option<(&'gcx hir::Expr, syntax::ast::NodeId)>, + id: hir::HirId, + expression: Option<(&'gcx hir::Expr, hir::HirId)>, ) -> DiagnosticBuilder<'a> { let mut db = fcx.report_mismatched_types(cause, expected, found, err); @@ -1257,7 +1258,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> // Verify that this is a tail expression of a function, otherwise the // label pointing out the cause for the type coercion will be wrong // as prior return coercions would not be relevant (#57664). - let parent_id = fcx.tcx.hir().get_parent_node(id); + let parent_id = fcx.tcx.hir().get_parent_node_by_hir_id(id); let fn_decl = if let Some((expr, blk_id)) = expression { pointing_at_return_type = fcx.suggest_mismatched_types_on_tail( &mut db, @@ -1267,7 +1268,7 @@ impl<'gcx, 'tcx, 'exprs, E> CoerceMany<'gcx, 'tcx, 'exprs, E> cause.span, blk_id, ); - let parent = fcx.tcx.hir().get(parent_id); + let parent = fcx.tcx.hir().get_by_hir_id(parent_id); fcx.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) } else { fcx.get_fn_decl(parent_id) diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index c6b34672e6b4c..e061a5304eb28 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -4,7 +4,7 @@ use rustc::ty::{self, TyCtxt, GenericParamDefKind}; use rustc::ty::util::ExplicitSelf; use rustc::traits::{self, ObligationCause, ObligationCauseCode, Reveal}; use rustc::ty::error::{ExpectedFound, TypeError}; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts, SubstsRef}; use rustc::util::common::ErrorReported; use errors::Applicability; @@ -160,7 +160,7 @@ fn compare_predicate_entailment<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // a fresh FulfillmentCtxt, and invoke select_all_or_error. // Create mapping from impl to placeholder. - let impl_to_skol_substs = Substs::identity_for_item(tcx, impl_m.def_id); + let impl_to_skol_substs = InternalSubsts::identity_for_item(tcx, impl_m.def_id); // Create mapping from trait to placeholder. let trait_to_skol_substs = impl_to_skol_substs.rebase_onto(tcx, @@ -361,7 +361,7 @@ fn check_region_bounds_on_impl_method<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, trait_m: &ty::AssociatedItem, trait_generics: &ty::Generics, impl_generics: &ty::Generics, - trait_to_skol_substs: &Substs<'tcx>) + trait_to_skol_substs: SubstsRef<'tcx>) -> Result<(), ErrorReported> { let trait_params = trait_generics.own_counts().lifetimes; let impl_params = impl_generics.own_counts().lifetimes; diff --git a/src/librustc_typeck/check/demand.rs b/src/librustc_typeck/check/demand.rs index adff5f2f9b9c8..f736e7ac29d08 100644 --- a/src/librustc_typeck/check/demand.rs +++ b/src/librustc_typeck/check/demand.rs @@ -2,7 +2,6 @@ use crate::check::FnCtxt; use rustc::infer::InferOk; use rustc::traits::{ObligationCause, ObligationCauseCode}; -use syntax::ast; use syntax::util::parser::PREC_POSTFIX; use syntax_pos::Span; use rustc::hir; @@ -164,7 +163,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { probe::Mode::MethodCall, expected, checked_ty, - ast::DUMMY_NODE_ID); + hir::DUMMY_HIR_ID); methods.retain(|m| { self.has_no_input_arg(m) && self.tcx.get_attrs(m.def_id).iter() @@ -218,15 +217,15 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let hir::def::Def::Local(id) = path.def { let parent = self.tcx.hir().get_parent_node(id); if let Some(Node::Expr(hir::Expr { - id, + hir_id, node: hir::ExprKind::Closure(_, decl, ..), .. })) = self.tcx.hir().find(parent) { - let parent = self.tcx.hir().get_parent_node(*id); + let parent = self.tcx.hir().get_parent_node_by_hir_id(*hir_id); if let (Some(Node::Expr(hir::Expr { node: hir::ExprKind::MethodCall(path, span, expr), .. - })), 1) = (self.tcx.hir().find(parent), decl.inputs.len()) { + })), 1) = (self.tcx.hir().find_by_hir_id(parent), decl.inputs.len()) { let self_ty = self.tables.borrow().node_type(expr[0].hir_id); let self_ty = format!("{:?}", self_ty); let name = path.ident.as_str(); @@ -470,8 +469,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { checked_ty: Ty<'tcx>, expected_ty: Ty<'tcx>, ) -> bool { - let parent_id = self.tcx.hir().get_parent_node(expr.id); - if let Some(parent) = self.tcx.hir().find(parent_id) { + let parent_id = self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id); + if let Some(parent) = self.tcx.hir().find_by_hir_id(parent_id) { // Shouldn't suggest `.into()` on `const`s. if let Node::Item(Item { node: ItemKind::Const(_, _), .. }) = parent { // FIXME(estebank): modify once we decide to suggest `as` casts @@ -501,10 +500,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some(hir::Node::Expr(hir::Expr { node: hir::ExprKind::Struct(_, fields, _), .. - })) = self.tcx.hir().find(self.tcx.hir().get_parent_node(expr.id)) { + })) = self.tcx.hir().find_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr.hir_id)) { // `expr` is a literal field for a struct, only suggest if appropriate for field in fields { - if field.expr.id == expr.id && field.is_shorthand { + if field.expr.hir_id == expr.hir_id && field.is_shorthand { // This is a field literal prefix = format!("{}: ", field.ident); break; diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index ad74e78fecdcd..12c7484f0f921 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -6,7 +6,7 @@ use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, InferOk, SuppressRegionErrors}; use rustc::middle::region; use rustc::traits::{ObligationCause, TraitEngine, TraitEngineExt}; -use rustc::ty::subst::{Subst, Substs, UnpackedKind}; +use rustc::ty::subst::{Subst, SubstsRef, UnpackedKind}; use rustc::ty::{self, Ty, TyCtxt}; use crate::util::common::ErrorReported; @@ -145,7 +145,7 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'a, 'tcx>( drop_impl_did: DefId, dtor_predicates: &ty::GenericPredicates<'tcx>, self_type_did: DefId, - self_to_impl_substs: &Substs<'tcx>, + self_to_impl_substs: SubstsRef<'tcx>, ) -> Result<(), ErrorReported> { let mut result = Ok(()); diff --git a/src/librustc_typeck/check/intrinsic.rs b/src/librustc_typeck/check/intrinsic.rs index 3b174b55f2ba0..924ced2e2a3c7 100644 --- a/src/librustc_typeck/check/intrinsic.rs +++ b/src/librustc_typeck/check/intrinsic.rs @@ -337,7 +337,7 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, "va_start" | "va_end" => { match mk_va_list_ty() { Some(va_list_ty) => (0, vec![va_list_ty], tcx.mk_unit()), - None => bug!("va_list lang_item must be defined to use va_list intrinsics") + None => bug!("`va_list` language item needed for C-variadic intrinsics") } } @@ -364,14 +364,14 @@ pub fn check_intrinsic_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, }; (0, vec![tcx.mk_imm_ref(tcx.mk_region(env_region), va_list_ty)], ret_ty) } - None => bug!("va_list lang_item must be defined to use va_list intrinsics") + None => bug!("`va_list` language item needed for C-variadic intrinsics") } } "va_arg" => { match mk_va_list_ty() { Some(va_list_ty) => (1, vec![va_list_ty], param(0)), - None => bug!("va_list lang_item must be defined to use va_list intrinsics") + None => bug!("`va_list` language item needed for C-variadic intrinsics") } } diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 1eaa8b17d09f7..996d6cfd56830 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -4,10 +4,9 @@ use crate::astconv::AstConv; use crate::check::{FnCtxt, PlaceOp, callee, Needs}; use crate::hir::GenericArg; use crate::hir::def_id::DefId; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{Subst, SubstsRef}; use rustc::traits; use rustc::ty::{self, Ty, GenericParamDefKind}; -use rustc::ty::subst::Subst; use rustc::ty::adjustment::{Adjustment, Adjust, OverloadedDeref}; use rustc::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::fold::TypeFoldable; @@ -209,7 +208,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { fn fresh_receiver_substs(&mut self, self_ty: Ty<'tcx>, pick: &probe::Pick<'tcx>) - -> &'tcx Substs<'tcx> { + -> SubstsRef<'tcx> { match pick.kind { probe::InherentImplPick => { let impl_def_id = pick.item.container.id(); @@ -300,8 +299,8 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { &mut self, pick: &probe::Pick<'tcx>, seg: &hir::PathSegment, - parent_substs: &Substs<'tcx>, - ) -> &'tcx Substs<'tcx> { + parent_substs: SubstsRef<'tcx>, + ) -> SubstsRef<'tcx> { // Determine the values for the generic parameters of the method. // If they were not explicitly supplied, just construct fresh // variables. @@ -369,7 +368,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { // until we unify the `Self` type. fn instantiate_method_sig(&mut self, pick: &probe::Pick<'tcx>, - all_substs: &'tcx Substs<'tcx>) + all_substs: SubstsRef<'tcx>) -> (ty::FnSig<'tcx>, ty::InstantiatedPredicates<'tcx>) { debug!("instantiate_method_sig(pick={:?}, all_substs={:?})", pick, @@ -404,7 +403,7 @@ impl<'a, 'gcx, 'tcx> ConfirmContext<'a, 'gcx, 'tcx> { fn add_obligations(&mut self, fty: Ty<'tcx>, - all_substs: &Substs<'tcx>, + all_substs: SubstsRef<'tcx>, method_predicates: &ty::InstantiatedPredicates<'tcx>) { debug!("add_obligations: fty={:?} all_substs={:?} method_predicates={:?}", fty, diff --git a/src/librustc_typeck/check/method/mod.rs b/src/librustc_typeck/check/method/mod.rs index 259a28645815f..d81d24e6d2b03 100644 --- a/src/librustc_typeck/check/method/mod.rs +++ b/src/librustc_typeck/check/method/mod.rs @@ -18,7 +18,7 @@ use rustc::hir; use rustc::hir::def::Def; use rustc::hir::def_id::DefId; use rustc::traits; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, Ty, ToPredicate, ToPolyTraitRef, TraitRef, TypeFoldable}; use rustc::ty::GenericParamDefKind; use rustc::ty::subst::Subst; @@ -38,7 +38,7 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { pub struct MethodCallee<'tcx> { /// Impl method ID, for inherent methods, or trait method ID, otherwise. pub def_id: DefId, - pub substs: &'tcx Substs<'tcx>, + pub substs: SubstsRef<'tcx>, /// Instantiated method signature, i.e., it has been /// substituted, normalized, and has had late-bound @@ -105,7 +105,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn method_exists(&self, method_name: ast::Ident, self_ty: Ty<'tcx>, - call_expr_id: ast::NodeId, + call_expr_id: hir::HirId, allow_private: bool) -> bool { let mode = probe::Mode::MethodCall; @@ -131,7 +131,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { msg: &str, method_name: ast::Ident, self_ty: Ty<'tcx>, - call_expr_id: ast::NodeId, + call_expr_id: hir::HirId, ) { let has_params = self .probe_for_name( @@ -202,7 +202,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { .unwrap().insert(import_def_id); } - self.tcx.check_stability(pick.item.def_id, Some(call_expr.id), span); + self.tcx.check_stability(pick.item.def_id, Some(call_expr.hir_id), span); let result = self.confirm_method( span, @@ -255,7 +255,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let mode = probe::Mode::MethodCall; let self_ty = self.resolve_type_vars_if_possible(&self_ty); self.probe_for_name(span, mode, method_name, IsSuggestion(false), - self_ty, call_expr.id, scope) + self_ty, call_expr.hir_id, scope) } /// `lookup_method_in_trait` is used for overloaded operators. @@ -281,7 +281,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { trait_def_id); // Construct a trait-reference `self_ty : Trait` - let substs = Substs::for_item(self.tcx, trait_def_id, |param, _| { + let substs = InternalSubsts::for_item(self.tcx, trait_def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => {} GenericParamDefKind::Type {..} => { @@ -399,7 +399,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span: Span, method_name: ast::Ident, self_ty: Ty<'tcx>, - expr_id: ast::NodeId + expr_id: hir::HirId ) -> Result> { debug!( "resolve_ufcs: method_name={:?} self_ty={:?} expr_id={:?}", diff --git a/src/librustc_typeck/check/method/probe.rs b/src/librustc_typeck/check/method/probe.rs index 04352626190f3..a4624eebcba83 100644 --- a/src/librustc_typeck/check/method/probe.rs +++ b/src/librustc_typeck/check/method/probe.rs @@ -13,7 +13,7 @@ use rustc_data_structures::sync::Lrc; use rustc::hir; use rustc::lint; use rustc::session::config::nightly_options; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts, SubstsRef}; use rustc::traits::{self, ObligationCause}; use rustc::traits::query::{CanonicalTyGoal}; use rustc::traits::query::method_autoderef::{CandidateStep, MethodAutoderefStepsResult}; @@ -125,7 +125,7 @@ struct Candidate<'tcx> { #[derive(Debug)] enum CandidateKind<'tcx> { - InherentImplCandidate(&'tcx Substs<'tcx>, + InherentImplCandidate(SubstsRef<'tcx>, // Normalize obligations Vec>), ObjectCandidate, @@ -209,7 +209,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { mode: Mode, return_type: Ty<'tcx>, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId) + scope_expr_id: hir::HirId) -> Vec { debug!("probe(self_ty={:?}, return_type={}, scope_expr_id={})", self_ty, @@ -238,7 +238,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { item_name: ast::Ident, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId, + scope_expr_id: hir::HirId, scope: ProbeScope) -> PickResult<'tcx> { debug!("probe(self_ty={:?}, item_name={}, scope_expr_id={})", @@ -263,7 +263,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { return_type: Option>, is_suggestion: IsSuggestion, self_ty: Ty<'tcx>, - scope_expr_id: ast::NodeId, + scope_expr_id: hir::HirId, scope: ProbeScope, op: OP) -> Result> @@ -340,7 +340,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { "the type of this value must be known \ to call a method on a raw pointer on it"); } else { - self.tcx.lint_node( + self.tcx.lint_hir( lint::builtin::TYVAR_BEHIND_RAW_POINTER, scope_expr_id, span, @@ -825,13 +825,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } fn assemble_extension_candidates_for_traits_in_scope(&mut self, - expr_id: ast::NodeId) + expr_hir_id: hir::HirId) -> Result<(), MethodError<'tcx>> { - if expr_id == ast::DUMMY_NODE_ID { + if expr_hir_id == hir::DUMMY_HIR_ID { return Ok(()) } let mut duplicates = FxHashSet::default(); - let expr_hir_id = self.tcx.hir().node_to_hir_id(expr_id); let opt_applicable_traits = self.tcx.in_scope_traits(expr_hir_id); if let Some(applicable_traits) = opt_applicable_traits { for trait_candidate in applicable_traits.iter() { @@ -1415,7 +1414,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { steps, IsSuggestion(true)); pcx.allow_similar_names = true; pcx.assemble_inherent_candidates(); - pcx.assemble_extension_candidates_for_traits_in_scope(ast::DUMMY_NODE_ID)?; + pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID)?; let method_names = pcx.candidate_method_names(); pcx.allow_similar_names = false; @@ -1425,7 +1424,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { pcx.reset(); pcx.method_name = Some(method_name); pcx.assemble_inherent_candidates(); - pcx.assemble_extension_candidates_for_traits_in_scope(ast::DUMMY_NODE_ID) + pcx.assemble_extension_candidates_for_traits_in_scope(hir::DUMMY_HIR_ID) .ok().map_or(None, |_| { pcx.pick_core() .and_then(|pick| pick.ok()) @@ -1481,7 +1480,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { fn xform_self_ty(&self, item: &ty::AssociatedItem, impl_ty: Ty<'tcx>, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> (Ty<'tcx>, Option>) { if item.kind == ty::AssociatedKind::Method && self.mode == Mode::MethodCall { let sig = self.xform_method_sig(item.def_id, substs); @@ -1493,7 +1492,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { fn xform_method_sig(&self, method: DefId, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> ty::FnSig<'tcx> { let fn_sig = self.tcx.fn_sig(method); @@ -1518,7 +1517,7 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { if generics.params.is_empty() { xform_fn_sig.subst(self.tcx, substs) } else { - let substs = Substs::for_item(self.tcx, method, |param, _| { + let substs = InternalSubsts::for_item(self.tcx, method, |param, _| { let i = param.index as usize; if i < substs.len() { substs[i] @@ -1538,12 +1537,12 @@ impl<'a, 'gcx, 'tcx> ProbeContext<'a, 'gcx, 'tcx> { } /// Gets the type of an impl and generate substitutions with placeholders. - fn impl_ty_and_substs(&self, impl_def_id: DefId) -> (Ty<'tcx>, &'tcx Substs<'tcx>) { + fn impl_ty_and_substs(&self, impl_def_id: DefId) -> (Ty<'tcx>, SubstsRef<'tcx>) { (self.tcx.type_of(impl_def_id), self.fresh_item_substs(impl_def_id)) } - fn fresh_item_substs(&self, def_id: DefId) -> &'tcx Substs<'tcx> { - Substs::for_item(self.tcx, def_id, |param, _| { + fn fresh_item_substs(&self, def_id: DefId) -> SubstsRef<'tcx> { + InternalSubsts::for_item(self.tcx, def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => self.tcx.types.re_erased.into(), GenericParamDefKind::Type {..} => { diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 2128466515123..3a430f77b6c64 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -109,7 +109,7 @@ use rustc::ty::{ use rustc::ty::adjustment::{Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability}; use rustc::ty::fold::TypeFoldable; use rustc::ty::query::Providers; -use rustc::ty::subst::{UnpackedKind, Subst, Substs, UserSelfTy, UserSubsts}; +use rustc::ty::subst::{UnpackedKind, Subst, InternalSubsts, SubstsRef, UserSelfTy, UserSubsts}; use rustc::ty::util::{Representability, IntTypeExt, Discr}; use rustc::ty::layout::VariantIdx; use syntax_pos::{self, BytePos, Span, MultiSpan}; @@ -130,14 +130,14 @@ use std::mem::replace; use std::ops::{self, Deref}; use std::slice; -use crate::require_c_abi_if_variadic; +use crate::require_c_abi_if_c_variadic; use crate::session::{CompileIncomplete, Session}; use crate::session::config::EntryFnType; use crate::TypeAndSubsts; use crate::lint; use crate::util::captures::Captures; use crate::util::common::{ErrorReported, indenter}; -use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, NodeMap}; +use crate::util::nodemap::{DefIdMap, DefIdSet, FxHashMap, FxHashSet, HirIdMap, NodeMap}; pub use self::Expectation::*; use self::autoderef::Autoderef; @@ -388,14 +388,14 @@ impl Needs { #[derive(Copy, Clone)] pub struct UnsafetyState { - pub def: ast::NodeId, + pub def: hir::HirId, pub unsafety: hir::Unsafety, pub unsafe_push_count: u32, from_fn: bool } impl UnsafetyState { - pub fn function(unsafety: hir::Unsafety, def: ast::NodeId) -> UnsafetyState { + pub fn function(unsafety: hir::Unsafety, def: hir::HirId) -> UnsafetyState { UnsafetyState { def: def, unsafety: unsafety, unsafe_push_count: 0, from_fn: true } } @@ -410,11 +410,11 @@ impl UnsafetyState { unsafety => { let (unsafety, def, count) = match blk.rules { hir::PushUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_add(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_add(1).unwrap()), hir::PopUnsafeBlock(..) => - (unsafety, blk.id, self.unsafe_push_count.checked_sub(1).unwrap()), + (unsafety, blk.hir_id, self.unsafe_push_count.checked_sub(1).unwrap()), hir::UnsafeBlock(..) => - (hir::Unsafety::Unsafe, blk.id, self.unsafe_push_count), + (hir::Unsafety::Unsafe, blk.hir_id, self.unsafe_push_count), hir::DefaultBlock => (unsafety, self.def, self.unsafe_push_count), }; @@ -497,11 +497,11 @@ pub struct BreakableCtxt<'gcx: 'tcx, 'tcx> { pub struct EnclosingBreakables<'gcx: 'tcx, 'tcx> { stack: Vec>, - by_id: NodeMap, + by_id: HirIdMap, } impl<'gcx, 'tcx> EnclosingBreakables<'gcx, 'tcx> { - fn find_breakable(&mut self, target_id: ast::NodeId) -> &mut BreakableCtxt<'gcx, 'tcx> { + fn find_breakable(&mut self, target_id: hir::HirId) -> &mut BreakableCtxt<'gcx, 'tcx> { let ix = *self.by_id.get(&target_id).unwrap_or_else(|| { bug!("could not find enclosing breakable with id {}", target_id); }); @@ -770,10 +770,10 @@ fn adt_destructor<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, /// (notably closures), `typeck_tables(def_id)` would wind up /// redirecting to the owning function. fn primary_body_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - id: ast::NodeId) + id: hir::HirId) -> Option<(hir::BodyId, Option<&'tcx hir::FnDecl>)> { - match tcx.hir().get(id) { + match tcx.hir().get_by_hir_id(id) { Node::Item(item) => { match item.node { hir::ItemKind::Const(_, body) | @@ -820,7 +820,7 @@ fn has_typeck_tables<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return tcx.has_typeck_tables(outer_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); primary_body_of(tcx, id).is_some() } @@ -840,8 +840,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, return tcx.typeck_tables_of(outer_def_id); } - let id = tcx.hir().as_local_node_id(def_id).unwrap(); - let span = tcx.hir().span(id); + let id = tcx.hir().as_local_hir_id(def_id).unwrap(); + let span = tcx.hir().span_by_hir_id(id); // Figure out what primary body this item has. let (body_id, fn_decl) = primary_body_of(tcx, id).unwrap_or_else(|| { @@ -925,8 +925,8 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // Consistency check our TypeckTables instance can hold all ItemLocalIds // it will need to hold. - assert_eq!(tables.local_id_root, - Some(DefId::local(tcx.hir().definitions().node_to_hir_id(id).owner))); + assert_eq!(tables.local_id_root, Some(DefId::local(id.owner))); + tables } @@ -939,7 +939,7 @@ fn check_abi<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, span: Span, abi: Abi) { struct GatherLocalsVisitor<'a, 'gcx: 'a+'tcx, 'tcx: 'a> { fcx: &'a FnCtxt<'a, 'gcx, 'tcx>, - parent_id: ast::NodeId, + parent_id: hir::HirId, } impl<'a, 'gcx, 'tcx> GatherLocalsVisitor<'a, 'gcx, 'tcx> { @@ -1051,7 +1051,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, param_env: ty::ParamEnv<'tcx>, fn_sig: ty::FnSig<'tcx>, decl: &'gcx hir::FnDecl, - fn_id: ast::NodeId, + fn_id: hir::HirId, body: &'gcx hir::Body, can_be_generator: Option) -> (FnCtxt<'a, 'gcx, 'tcx>, Option>) @@ -1072,7 +1072,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fn_sig = fcx.tcx.mk_fn_sig( fn_sig.inputs().iter().cloned(), revealed_ret_ty, - fn_sig.variadic, + fn_sig.c_variadic, fn_sig.unsafety, fn_sig.abi ); @@ -1085,9 +1085,9 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.yield_ty = Some(yield_ty); } - let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id(fn_id)); - let outer_node_id = fcx.tcx.hir().as_local_node_id(outer_def_id).unwrap(); - GatherLocalsVisitor { fcx: &fcx, parent_id: outer_node_id, }.visit_body(body); + let outer_def_id = fcx.tcx.closure_base_def_id(fcx.tcx.hir().local_def_id_from_hir_id(fn_id)); + 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); // Add formal parameters. for (arg_ty, arg) in fn_sig.inputs().iter().zip(&body.arguments) { @@ -1110,8 +1110,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, fcx.write_ty(arg.hir_id, arg_ty); } - let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); - inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_hir_id, fn_sig); + inherited.tables.borrow_mut().liberated_fn_sigs_mut().insert(fn_id, fn_sig); fcx.check_return_expr(&body.value); @@ -1164,14 +1163,13 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that the main return type implements the termination trait. if let Some(term_id) = fcx.tcx.lang_items().termination() { if let Some((def_id, EntryFnType::Main)) = fcx.tcx.entry_fn(LOCAL_CRATE) { - let main_id = fcx.tcx.hir().as_local_node_id(def_id).unwrap(); + let main_id = fcx.tcx.hir().as_local_hir_id(def_id).unwrap(); if main_id == fn_id { let substs = fcx.tcx.mk_substs_trait(declared_ret_ty, &[]); let trait_ref = ty::TraitRef::new(term_id, substs); let return_ty_span = decl.output.span(); - let fn_hir_id = fcx.tcx.hir().node_to_hir_id(fn_id); let cause = traits::ObligationCause::new( - return_ty_span, fn_hir_id, ObligationCauseCode::MainFunctionType); + return_ty_span, fn_id, ObligationCauseCode::MainFunctionType); inherited.register_predicate( traits::Obligation::new( @@ -1182,7 +1180,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !` if let Some(panic_impl_did) = fcx.tcx.lang_items().panic_impl() { - if panic_impl_did == fcx.tcx.hir().local_def_id(fn_id) { + if panic_impl_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(panic_info_did) = fcx.tcx.lang_items().panic_info() { // at this point we don't care if there are duplicate handlers or if the handler has // the wrong signature as this value we'll be used when writing metadata and that @@ -1197,7 +1195,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span(fn_id); + let span = fcx.tcx.hir().span_by_hir_id(fn_id); if inputs.len() == 1 { let arg_is_panic_info = match inputs[0].sty { ty::Ref(region, ty, mutbl) => match ty.sty { @@ -1218,7 +1216,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1240,7 +1238,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, // Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !` if let Some(alloc_error_handler_did) = fcx.tcx.lang_items().oom() { - if alloc_error_handler_did == fcx.tcx.hir().local_def_id(fn_id) { + if alloc_error_handler_did == fcx.tcx.hir().local_def_id_from_hir_id(fn_id) { if let Some(alloc_layout_did) = fcx.tcx.lang_items().alloc_layout() { if declared_ret_ty.sty != ty::Never { fcx.tcx.sess.span_err( @@ -1250,7 +1248,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, } let inputs = fn_sig.inputs(); - let span = fcx.tcx.hir().span(fn_id); + let span = fcx.tcx.hir().span_by_hir_id(fn_id); if inputs.len() == 1 { let arg_is_alloc_layout = match inputs[0].sty { ty::Adt(ref adt, _) => { @@ -1266,7 +1264,7 @@ fn check_fn<'a, 'gcx, 'tcx>(inherited: &'a Inherited<'a, 'gcx, 'tcx>, ); } - if let Node::Item(item) = fcx.tcx.hir().get(fn_id) { + if let Node::Item(item) = fcx.tcx.hir().get_by_hir_id(fn_id) { if let ItemKind::Fn(_, _, ref generics, _) = item.node { if !generics.params.is_empty() { fcx.tcx.sess.span_err( @@ -1320,7 +1318,7 @@ fn check_union<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, fn check_opaque<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, span: Span, ) { if let Err(partially_expanded_type) = tcx.try_expand_impl_trait_type(def_id, substs) { @@ -1387,7 +1385,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite hir::ItemKind::Existential(..) => { let def_id = tcx.hir().local_def_id(it.id); - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); check_opaque(tcx, def_id, substs, it.span); } hir::ItemKind::Ty(..) => { @@ -1428,7 +1426,7 @@ pub fn check_item_type<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, it: &'tcx hir::Ite } if let hir::ForeignItemKind::Fn(ref fn_decl, _, _) = item.node { - require_c_abi_if_variadic(tcx, fn_decl, m.abi, item.span); + require_c_abi_if_c_variadic(tcx, fn_decl, m.abi, item.span); } } } @@ -1811,7 +1809,7 @@ fn check_transparent<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: De // For each field, figure out if it's known to be a ZST and align(1) let field_infos = adt.non_enum_variant().fields.iter().map(|field| { - let ty = field.ty(tcx, Substs::identity_for_item(tcx, field.did)); + let ty = field.ty(tcx, InternalSubsts::identity_for_item(tcx, field.did)); let param_env = tcx.param_env(field.did); let layout = tcx.layout_of(param_env.and(ty)); // We are currently checking the type this field came from, so it must be local @@ -2030,7 +2028,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ret_coercion_span: RefCell::new(None), yield_ty: None, ps: RefCell::new(UnsafetyState::function(hir::Unsafety::Normal, - ast::CRATE_NODE_ID)), + hir::CRATE_HIR_ID)), diverges: Cell::new(Diverges::Maybe), has_errors: Cell::new(false), enclosing_breakables: RefCell::new(EnclosingBreakables { @@ -2051,13 +2049,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// Produces warning on the given node, if the current point in the /// function is unreachable, and there hasn't been another warning. - fn warn_if_unreachable(&self, id: ast::NodeId, span: Span, kind: &str) { + fn warn_if_unreachable(&self, id: hir::HirId, span: Span, kind: &str) { if self.diverges.get() == Diverges::Always { self.diverges.set(Diverges::WarnedAlways); debug!("warn_if_unreachable: id={:?} span={:?} kind={}", id, span, kind); - self.tcx().lint_node( + self.tcx().lint_hir( lint::builtin::UNREACHABLE_CODE, id, span, &format!("unreachable {}", kind)); @@ -2145,8 +2143,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - pub fn write_field_index(&self, node_id: ast::NodeId, index: usize) { - let hir_id = self.tcx.hir().node_to_hir_id(node_id); + pub fn write_field_index(&self, hir_id: hir::HirId, index: usize) { self.tables.borrow_mut().field_indices_mut().insert(hir_id, index); } @@ -2180,7 +2177,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if !method_generics.params.is_empty() { let user_type_annotation = self.infcx.probe(|_| { let user_substs = UserSubsts { - substs: Substs::for_item(self.tcx, method.def_id, |param, _| { + substs: InternalSubsts::for_item(self.tcx, method.def_id, |param, _| { let i = param.index as usize; if i < method_generics.parent_count { self.infcx.var_for_def(DUMMY_SP, param) @@ -2203,7 +2200,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - pub fn write_substs(&self, node_id: hir::HirId, substs: &'tcx Substs<'tcx>) { + pub fn write_substs(&self, node_id: hir::HirId, substs: SubstsRef<'tcx>) { if !substs.is_noop() { debug!("write_substs({:?}, {:?}) in fcx {}", node_id, @@ -2225,7 +2222,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { &self, hir_id: hir::HirId, def_id: DefId, - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, user_self_ty: Option>, ) { debug!( @@ -2306,7 +2303,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// types as well. This function combines the two. fn instantiate_type_scheme(&self, span: Span, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, value: &T) -> T where T : TypeFoldable<'tcx> @@ -2322,7 +2319,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// As `instantiate_type_scheme`, but for the bounds found in a /// generic type scheme. - fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: &Substs<'tcx>) + fn instantiate_bounds(&self, span: Span, def_id: DefId, substs: SubstsRef<'tcx>) -> ty::InstantiatedPredicates<'tcx> { let bounds = self.tcx.predicates_of(def_id); let result = bounds.instantiate(self.tcx, substs); @@ -2339,10 +2336,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// `InferCtxt::instantiate_opaque_types` for more details. fn instantiate_opaque_types_from_value>( &self, - parent_id: ast::NodeId, + parent_id: hir::HirId, value: &T, ) -> T { - let parent_def_id = self.tcx.hir().local_def_id(parent_id); + let parent_def_id = self.tcx.hir().local_def_id_from_hir_id(parent_id); debug!("instantiate_opaque_types_from_value(parent_def_id={:?}, value={:?})", parent_def_id, value); @@ -2480,7 +2477,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Registers obligations that all types appearing in `substs` are well-formed. - pub fn add_wf_bounds(&self, substs: &Substs<'tcx>, expr: &hir::Expr) { + pub fn add_wf_bounds(&self, substs: SubstsRef<'tcx>, expr: &hir::Expr) { for ty in substs.types() { self.register_wf_obligation(ty, expr.span, traits::MiscObligation); } @@ -2524,7 +2521,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn field_ty(&self, span: Span, field: &'tcx ty::FieldDef, - substs: &Substs<'tcx>) + substs: SubstsRef<'tcx>) -> Ty<'tcx> { self.normalize_associated_types_in(span, &field.ty(self.tcx, substs)) @@ -2786,7 +2783,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { &method.sig.inputs()[1..] ); self.check_argument_types(sp, expr_sp, &method.sig.inputs()[1..], &expected_arg_tys[..], - args_no_rcvr, method.sig.variadic, tuple_arguments, + args_no_rcvr, method.sig.c_variadic, tuple_arguments, self.tcx.hir().span_if_local(method.def_id)); method.sig.output() } @@ -2865,7 +2862,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn_inputs: &[Ty<'tcx>], mut expected_arg_tys: &[Ty<'tcx>], args: &'gcx [hir::Expr], - variadic: bool, + c_variadic: bool, tuple_arguments: TupleArgumentsFlag, def_span: Option) { let tcx = self.tcx; @@ -2889,11 +2886,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let param_count_error = |expected_count: usize, arg_count: usize, error_code: &str, - variadic: bool, + c_variadic: bool, sugg_unit: bool| { let mut err = tcx.sess.struct_span_err_with_code(sp, &format!("this function takes {}{} but {} {} supplied", - if variadic {"at least "} else {""}, + if c_variadic { "at least " } else { "" }, potentially_plural_count(expected_count, "parameter"), potentially_plural_count(arg_count, "parameter"), if arg_count == 1 {"was"} else {"were"}), @@ -2913,7 +2910,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Applicability::MachineApplicable); } else { err.span_label(sp, format!("expected {}{}", - if variadic {"at least "} else {""}, + if c_variadic { "at least " } else { "" }, potentially_plural_count(expected_count, "parameter"))); } err.emit(); @@ -2947,7 +2944,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } else if expected_arg_count == supplied_arg_count { fn_inputs.to_vec() - } else if variadic { + } else if c_variadic { if supplied_arg_count >= expected_arg_count { fn_inputs.to_vec() } else { @@ -2994,10 +2991,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.select_obligations_where_possible(false); } - // For variadic functions, we don't have a declared type for all of + // For C-variadic functions, we don't have a declared type for all of // the arguments hence we only do our usual type checking with // the arguments who's types we do know. - let t = if variadic { + let t = if c_variadic { expected_arg_count } else if tuple_arguments == TupleArguments { args.len() @@ -3009,7 +3006,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // Closure arguments themselves can't be diverging, but // a previous argument can, e.g., `foo(panic!(), || {})`. if !check_closures { - self.warn_if_unreachable(arg.id, arg.span, "expression"); + self.warn_if_unreachable(arg.hir_id, arg.span, "expression"); } let is_closure = match arg.node { @@ -3046,7 +3043,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // We also need to make sure we at least write the ty of the other // arguments which we skipped above. - if variadic { + if c_variadic { fn variadic_error<'tcx>(s: &Session, span: Span, t: Ty<'tcx>, cast_ty: &str) { use crate::structured_errors::{VariadicError, StructuredDiagnostic}; VariadicError::new(s, span, t, cast_ty).diagnostic().emit(); @@ -3340,7 +3337,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ret_coercion.borrow_mut() .coerce(self, &self.cause(return_expr.span, - ObligationCauseCode::ReturnType(return_expr.id)), + ObligationCauseCode::ReturnType(return_expr.hir_id)), return_expr, return_expr_ty); } @@ -3511,13 +3508,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let field_ty = self.field_ty(expr.span, field, substs); // Save the index of all fields regardless of their visibility in case // of error recovery. - self.write_field_index(expr.id, index); + self.write_field_index(expr.hir_id, index); if field.vis.is_accessible_from(def_scope, self.tcx) { let adjustments = autoderef.adjust_steps(self, needs); self.apply_adjustments(base, adjustments); autoderef.finalize(self); - self.tcx.check_stability(field.did, Some(expr.id), expr.span); + self.tcx.check_stability(field.did, Some(expr.hir_id), expr.span); return field_ty; } private_candidate = Some((base_def.did, field_ty)); @@ -3532,7 +3529,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.apply_adjustments(base, adjustments); autoderef.finalize(self); - self.write_field_index(expr.id, index); + self.write_field_index(expr.hir_id, index); return field_ty; } } @@ -3549,31 +3546,33 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { "field `{}` of struct `{}` is private", field, struct_path); // Also check if an accessible method exists, which is often what is meant. - if self.method_exists(field, expr_t, expr.id, false) && !self.expr_in_place(expr.id) { + if self.method_exists(field, expr_t, expr.hir_id, false) + && !self.expr_in_place(expr.hir_id) + { self.suggest_method_call( &mut err, &format!("a method `{}` also exists, call it with parentheses", field), field, expr_t, - expr.id, + expr.hir_id, ); } err.emit(); field_ty } else if field.name == keywords::Invalid.name() { self.tcx().types.err - } else if self.method_exists(field, expr_t, expr.id, true) { + } else if self.method_exists(field, expr_t, expr.hir_id, true) { let mut err = type_error_struct!(self.tcx().sess, field.span, expr_t, E0615, "attempted to take value of method `{}` on type `{}`", field, expr_t); - if !self.expr_in_place(expr.id) { + if !self.expr_in_place(expr.hir_id) { self.suggest_method_call( &mut err, "use parentheses to call the method", field, expr_t, - expr.id + expr.hir_id ); } else { err.help("methods are immutable and cannot be assigned to"); @@ -3613,7 +3612,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ) { let base = self.tcx.sess.source_map() .span_to_snippet(base.span) - .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id)); + .unwrap_or_else(|_| + self.tcx.hir().hir_to_pretty_string(base.hir_id)); let help = "instead of using tuple indexing, use array indexing"; let suggestion = format!("{}[{}]", base, field); let applicability = if len < user_index { @@ -3629,7 +3629,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ty::RawPtr(..) => { let base = self.tcx.sess.source_map() .span_to_snippet(base.span) - .unwrap_or_else(|_| self.tcx.hir().node_to_pretty_string(base.id)); + .unwrap_or_else(|_| self.tcx.hir().hir_to_pretty_string(base.hir_id)); let msg = format!("`{}` is a raw pointer; try dereferencing it", base); let suggestion = format!("(*{}).{}", base, field); err.span_suggestion( @@ -3754,7 +3754,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_expr_struct_fields(&self, adt_ty: Ty<'tcx>, expected: Expectation<'tcx>, - expr_id: ast::NodeId, + expr_id: hir::HirId, span: Span, variant: &'tcx ty::VariantDef, ast_fields: &'gcx [hir::Field], @@ -3787,7 +3787,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let ident = tcx.adjust_ident(field.ident, variant.did, self.body_id).0; let field_type = if let Some((i, v_field)) = remaining_fields.remove(&ident) { seen_fields.insert(ident, field.span); - self.write_field_index(field.id, i); + self.write_field_index(field.hir_id, i); // We don't look at stability attributes on // struct-like enums (yet...), but it's definitely not @@ -3875,13 +3875,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { pub fn check_struct_path(&self, qpath: &QPath, - node_id: ast::NodeId) + hir_id: hir::HirId) -> Option<(&'tcx ty::VariantDef, Ty<'tcx>)> { let path_span = match *qpath { QPath::Resolved(_, ref path) => path.span, QPath::TypeRelative(ref qself, _) => qself.span }; - let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, node_id); + let (def, ty) = self.finish_resolving_struct_path(qpath, path_span, hir_id); let variant = match def { Def::Err => { self.set_tainted_by_errors(); @@ -3909,7 +3909,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { if let Some((variant, did, substs)) = variant { debug!("check_struct_path: did={:?} substs={:?}", did, substs); - let hir_id = self.tcx.hir().node_to_hir_id(node_id); self.write_user_type_annotation_from_substs(hir_id, did, substs, None); // Check bounds on type arguments used in the path. @@ -3938,7 +3937,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { // Find the relevant variant let (variant, adt_ty) = - if let Some(variant_ty) = self.check_struct_path(qpath, expr.id) { + if let Some(variant_ty) = self.check_struct_path(qpath, expr.hir_id) { variant_ty } else { self.check_struct_fields_on_error(fields, base_expr); @@ -3958,7 +3957,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { adt.variant_descr()); } - let error_happened = self.check_expr_struct_fields(adt_ty, expected, expr.id, path_span, + let error_happened = self.check_expr_struct_fields(adt_ty, expected, expr.hir_id, path_span, variant, fields, base_expr.is_none()); if let &Some(ref base_expr) = base_expr { // If check_expr_struct_fields hit an error, do not attempt to populate @@ -4007,7 +4006,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expr, expected); // Warn for expressions after diverging siblings. - self.warn_if_unreachable(expr.id, expr.span, "expression"); + self.warn_if_unreachable(expr.hir_id, expr.span, "expression"); // Hide the outer diverging and has_errors flags. let old_diverges = self.diverges.get(); @@ -4023,7 +4022,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ExprKind::Loop(..) | ExprKind::While(..) | ExprKind::If(..) | ExprKind::Match(..) => {} - _ => self.warn_if_unreachable(expr.id, expr.span, "expression") + _ => self.warn_if_unreachable(expr.hir_id, expr.span, "expression") } // Any expression that produces a value of type `!` must have diverged @@ -4040,7 +4039,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self.diverges.set(self.diverges.get() | old_diverges); self.has_errors.set(self.has_errors.get() | old_has_errors); - debug!("type of {} is...", self.tcx.hir().node_to_string(expr.id)); + debug!("type of {} is...", self.tcx.hir().hir_to_string(expr.hir_id)); debug!("... {:?}, expected is {:?}", ty, expected); ty @@ -4060,7 +4059,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ); let tcx = self.tcx; - let id = expr.id; + let id = expr.hir_id; match expr.node { ExprKind::Box(ref subexpr) => { let expected_inner = expected.to_option(self).map_or(NoExpectation, |ty| { @@ -4192,7 +4191,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } ExprKind::Path(ref qpath) => { - let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.id, expr.span); + let (def, opt_ty, segs) = self.resolve_ty_and_def_ufcs(qpath, expr.hir_id, + expr.span); let ty = match def { Def::Err => { self.set_tainted_by_errors(); @@ -4257,6 +4257,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } ExprKind::Break(destination, ref expr_opt) => { if let Ok(target_id) = destination.target_id { + let target_id = tcx.hir().node_to_hir_id(target_id); let (e_ty, cause); if let Some(ref e) = *expr_opt { // If this is a break with a value, we need to type-check @@ -4362,7 +4363,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { *self.ret_coercion_span.borrow_mut() = Some(expr.span); } let cause = self.cause(expr.span, ObligationCauseCode::ReturnNoExpression); - if let Some((fn_decl, _)) = self.get_fn_decl(expr.id) { + if let Some((fn_decl, _)) = self.get_fn_decl(expr.hir_id) { coercion.coerce_forced_unit( self, &cause, @@ -4424,7 +4425,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, // Will get updated if/when we find a `break`. }; - let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(expr.hir_id, ctxt, || { self.check_expr_has_type_or_error(&cond, tcx.types.bool); let cond_diverging = self.diverges.get(); self.check_block_no_value(&body); @@ -4460,7 +4461,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, // Will get updated if/when we find a `break`. }; - let (ctxt, ()) = self.with_breakable_ctxt(expr.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(expr.hir_id, ctxt, || { self.check_block_no_value(&body); }); @@ -4553,7 +4554,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ExprKind::Repeat(ref element, ref count) => { let count_def_id = tcx.hir().local_def_id(count.id); let param_env = ty::ParamEnv::empty(); - let substs = Substs::identity_for_item(tcx.global_tcx(), count_def_id); + let substs = InternalSubsts::identity_for_item(tcx.global_tcx(), count_def_id); let instance = ty::Instance::resolve( tcx.global_tcx(), param_env, @@ -4717,7 +4718,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn finish_resolving_struct_path(&self, qpath: &QPath, path_span: Span, - node_id: ast::NodeId) + hir_id: hir::HirId) -> (Def, Ty<'tcx>) { match *qpath { @@ -4734,11 +4735,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } else { Def::Err }; - let (ty, def) = AstConv::associated_path_to_ty(self, node_id, path_span, + let (ty, def) = AstConv::associated_path_to_ty(self, hir_id, path_span, ty, def, segment, true); // Write back the new resolution. - let hir_id = self.tcx.hir().node_to_hir_id(node_id); self.tables.borrow_mut().type_dependent_defs_mut().insert(hir_id, def); (def, ty) @@ -4750,11 +4750,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// definition. The newly resolved definition is written into `type_dependent_defs`. pub fn resolve_ty_and_def_ufcs<'b>(&self, qpath: &'b QPath, - node_id: ast::NodeId, + hir_id: hir::HirId, span: Span) -> (Def, Option>, &'b [hir::PathSegment]) { - debug!("resolve_ty_and_def_ufcs: qpath={:?} node_id={:?} span={:?}", qpath, node_id, span); + debug!("resolve_ty_and_def_ufcs: qpath={:?} hir_id={:?} span={:?}", qpath, hir_id, span); let (ty, qself, item_segment) = match *qpath { QPath::Resolved(ref opt_qself, ref path) => { return (path.def, @@ -4765,14 +4765,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { (self.to_ty(qself), qself, segment) } }; - let hir_id = self.tcx.hir().node_to_hir_id(node_id); if let Some(cached_def) = self.tables.borrow().type_dependent_defs().get(hir_id) { // Return directly on cache hit. This is useful to avoid doubly reporting // errors with default match binding modes. See #44614. return (*cached_def, Some(ty), slice::from_ref(&**item_segment)) } let item_name = item_segment.ident; - let def = match self.resolve_ufcs(span, item_name, ty, node_id) { + let def = match self.resolve_ufcs(span, item_name, ty, hir_id) { Ok(def) => def, Err(error) => { let def = match error { @@ -4854,7 +4853,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { hir::StmtKind::Local(..) | hir::StmtKind::Expr(..) | hir::StmtKind::Semi(..) => {} } - self.warn_if_unreachable(stmt.id, stmt.span, "statement"); + self.warn_if_unreachable(stmt.hir_id, stmt.span, "statement"); // Hide the outer diverging and `has_errors` flags. let old_diverges = self.diverges.get(); @@ -4936,7 +4935,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { may_break: false, }; - let (ctxt, ()) = self.with_breakable_ctxt(blk.id, ctxt, || { + let (ctxt, ()) = self.with_breakable_ctxt(blk.hir_id, ctxt, || { for s in &blk.stmts { self.check_stmt(s); } @@ -4946,12 +4945,12 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { let tail_expr_ty = tail_expr.map(|t| self.check_expr_with_expectation(t, expected)); let mut enclosing_breakables = self.enclosing_breakables.borrow_mut(); - let ctxt = enclosing_breakables.find_breakable(blk.id); + let ctxt = enclosing_breakables.find_breakable(blk.hir_id); let coerce = ctxt.coerce.as_mut().unwrap(); if let Some(tail_expr_ty) = tail_expr_ty { let tail_expr = tail_expr.unwrap(); let cause = self.cause(tail_expr.span, - ObligationCauseCode::BlockTailExpression(blk.id)); + ObligationCauseCode::BlockTailExpression(blk.hir_id)); coerce.coerce(self, &cause, tail_expr, @@ -4975,9 +4974,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // that highlight errors inline. let mut sp = blk.span; let mut fn_span = None; - if let Some((decl, ident)) = self.get_parent_fn_decl(blk.id) { + let blk_node_id = self.tcx.hir().hir_to_node_id(blk.hir_id); + if let Some((decl, ident)) = self.get_parent_fn_decl(blk_node_id) { let ret_sp = decl.output.span(); - if let Some(block_sp) = self.parent_item_span(blk.id) { + if let Some(block_sp) = self.parent_item_span(blk_node_id) { // HACK: on some cases (`ui/liveness/liveness-issue-2163.rs`) the // output would otherwise be incorrect and even misleading. Make sure // the span we're aiming at correspond to a `fn` body. @@ -5067,13 +5067,13 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - /// Given a `NodeId`, return the `FnDecl` of the method it is enclosed by and whether a + /// Given a `HirId`, return the `FnDecl` of the method it is enclosed by and whether a /// suggestion can be made, `None` otherwise. - pub fn get_fn_decl(&self, blk_id: ast::NodeId) -> Option<(hir::FnDecl, bool)> { + pub fn get_fn_decl(&self, blk_id: hir::HirId) -> Option<(hir::FnDecl, bool)> { // Get enclosing Fn, if it is a function or a trait method, unless there's a `loop` or // `while` before reaching it, as block tail returns are not available in them. self.tcx.hir().get_return_block(blk_id).and_then(|blk_id| { - let parent = self.tcx.hir().get(blk_id); + let parent = self.tcx.hir().get_by_hir_id(blk_id); self.get_node_fn_decl(parent).map(|(fn_decl, _, is_main)| (fn_decl, is_main)) }) } @@ -5090,7 +5090,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { expected: Ty<'tcx>, found: Ty<'tcx>, cause_span: Span, - blk_id: ast::NodeId, + blk_id: hir::HirId, ) -> bool { self.suggest_missing_semicolon(err, expression, expected, cause_span); let mut pointing_at_return_type = false; @@ -5303,14 +5303,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { self_ty: Option>, def: Def, span: Span, - node_id: ast::NodeId) + hir_id: hir::HirId) -> (Ty<'tcx>, Def) { debug!( - "instantiate_value_path(segments={:?}, self_ty={:?}, def={:?}, node_id={})", + "instantiate_value_path(segments={:?}, self_ty={:?}, def={:?}, hir_id={})", segments, self_ty, def, - node_id, + hir_id, ); let tcx = self.tcx; @@ -5380,7 +5380,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { Def::Local(nid) | Def::Upvar(nid, ..) => { let ty = self.local_ty(span, nid).decl_ty; let ty = self.normalize_associated_types_in(span, &ty); - self.write_ty(tcx.hir().node_to_hir_id(node_id), ty); + self.write_ty(hir_id, ty); return (ty, def); } _ => {} @@ -5532,7 +5532,6 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { assert!(!ty.has_escaping_bound_vars()); // First, store the "user substs" for later. - let hir_id = tcx.hir().node_to_hir_id(node_id); self.write_user_type_annotation_from_substs(hir_id, def_id, substs, user_self_ty); // Add all the obligations that are required, substituting and @@ -5566,10 +5565,10 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - self.check_rustc_args_require_const(def_id, node_id, span); + self.check_rustc_args_require_const(def_id, hir_id, span); debug!("instantiate_value_path: type of {:?} is {:?}", - node_id, + hir_id, ty_substituted); self.write_substs(hir_id, substs); @@ -5578,7 +5577,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn check_rustc_args_require_const(&self, def_id: DefId, - node_id: ast::NodeId, + hir_id: hir::HirId, span: Span) { // We're only interested in functions tagged with // #[rustc_args_required_const], so ignore anything that's not. @@ -5588,9 +5587,11 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { // If our calling expression is indeed the function itself, we're good! // If not, generate an error that this can only be called directly. - if let Node::Expr(expr) = self.tcx.hir().get(self.tcx.hir().get_parent_node(node_id)) { + if let Node::Expr(expr) = self.tcx.hir().get_by_hir_id( + self.tcx.hir().get_parent_node_by_hir_id(hir_id)) + { if let ExprKind::Call(ref callee, ..) = expr.node { - if callee.id == node_id { + if callee.hir_id == hir_id { return } } @@ -5618,7 +5619,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } } - fn with_breakable_ctxt R, R>(&self, id: ast::NodeId, + fn with_breakable_ctxt R, R>(&self, id: hir::HirId, ctxt: BreakableCtxt<'gcx, 'tcx>, f: F) -> (BreakableCtxt<'gcx, 'tcx>, R) { let index; @@ -5655,22 +5656,22 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { } /// Returns `true` if an expression is contained inside the LHS of an assignment expression. - fn expr_in_place(&self, mut expr_id: ast::NodeId) -> bool { + fn expr_in_place(&self, mut expr_id: hir::HirId) -> bool { let mut contained_in_place = false; while let hir::Node::Expr(parent_expr) = - self.tcx.hir().get(self.tcx.hir().get_parent_node(expr_id)) + self.tcx.hir().get_by_hir_id(self.tcx.hir().get_parent_node_by_hir_id(expr_id)) { match &parent_expr.node { hir::ExprKind::Assign(lhs, ..) | hir::ExprKind::AssignOp(_, lhs, ..) => { - if lhs.id == expr_id { + if lhs.hir_id == expr_id { contained_in_place = true; break; } } _ => (), } - expr_id = parent_expr.id; + expr_id = parent_expr.hir_id; } contained_in_place diff --git a/src/librustc_typeck/check/op.rs b/src/librustc_typeck/check/op.rs index e6b4523f9e7cc..9d883b22214f7 100644 --- a/src/librustc_typeck/check/op.rs +++ b/src/librustc_typeck/check/op.rs @@ -51,8 +51,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { { let tcx = self.tcx; - debug!("check_binop(expr.id={}, expr={:?}, op={:?}, lhs_expr={:?}, rhs_expr={:?})", - expr.id, + debug!("check_binop(expr.hir_id={}, expr={:?}, op={:?}, lhs_expr={:?}, rhs_expr={:?})", + expr.hir_id, expr, op, lhs_expr, @@ -150,8 +150,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { is_assign: IsAssign) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { - debug!("check_overloaded_binop(expr.id={}, op={:?}, is_assign={:?})", - expr.id, + debug!("check_overloaded_binop(expr.hir_id={}, op={:?}, is_assign={:?})", + expr.hir_id, op, is_assign); diff --git a/src/librustc_typeck/check/regionck.rs b/src/librustc_typeck/check/regionck.rs index 08bc861766b8e..b549986777c84 100644 --- a/src/librustc_typeck/check/regionck.rs +++ b/src/librustc_typeck/check/regionck.rs @@ -81,7 +81,7 @@ use rustc::hir::def_id::DefId; use rustc::infer::outlives::env::OutlivesEnvironment; use rustc::infer::{self, RegionObligation, SuppressRegionErrors}; use rustc::ty::adjustment; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty}; use rustc::hir::intravisit::{self, NestedVisitorMap, Visitor}; @@ -90,7 +90,6 @@ use rustc_data_structures::sync::Lrc; use std::mem; use std::ops::Deref; use std::rc::Rc; -use syntax::ast; use syntax_pos::Span; // a variation on try that just returns unit @@ -163,7 +162,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { /// rest of type check and because sometimes we need type /// inference to have completed before we can determine which /// constraints to add. - pub fn regionck_fn(&self, fn_id: ast::NodeId, body: &'gcx hir::Body) { + pub fn regionck_fn(&self, fn_id: hir::HirId, body: &'gcx hir::Body) { debug!("regionck_fn(id={})", fn_id); let subject = self.tcx.hir().body_owner_def_id(body.id()); let hir_id = body.value.hir_id; @@ -176,9 +175,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { ); if self.err_count_since_creation() == 0 { - let fn_hir_id = self.tcx.hir().node_to_hir_id(fn_id); // regionck assumes typeck succeeded - rcx.visit_fn_body(fn_hir_id, body, self.tcx.hir().span_by_hir_id(fn_hir_id)); + rcx.visit_fn_body(fn_id, body, self.tcx.hir().span_by_hir_id(fn_id)); } rcx.resolve_regions_and_report_errors(SuppressRegionErrors::when_nll_is_enabled(self.tcx)); @@ -696,8 +694,8 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for RegionCtxt<'a, 'gcx, 'tcx> { hir::ExprKind::Ret(Some(ref ret_expr)) => { let call_site_scope = self.call_site_scope; debug!( - "visit_expr ExprKind::Ret ret_expr.id {} call_site_scope: {:?}", - ret_expr.id, call_site_scope + "visit_expr ExprKind::Ret ret_expr.hir_id {} call_site_scope: {:?}", + ret_expr.hir_id, call_site_scope ); let call_site_region = self.tcx.mk_region(ty::ReScope(call_site_scope.unwrap())); self.type_of_node_must_outlive( @@ -1395,7 +1393,7 @@ impl<'a, 'gcx, 'tcx> RegionCtxt<'a, 'gcx, 'tcx> { fn substs_wf_in_scope( &mut self, origin: infer::ParameterOrigin, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, expr_span: Span, expr_region: ty::Region<'tcx>, ) { diff --git a/src/librustc_typeck/check/upvar.rs b/src/librustc_typeck/check/upvar.rs index 1a165e6ff1eb8..bf6f4482e746d 100644 --- a/src/librustc_typeck/check/upvar.rs +++ b/src/librustc_typeck/check/upvar.rs @@ -67,7 +67,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> { let body = self.fcx.tcx.hir().body(body_id); self.visit_body(body); self.fcx - .analyze_closure(expr.id, expr.hir_id, expr.span, body, cc); + .analyze_closure(expr.hir_id, expr.span, body, cc); } intravisit::walk_expr(self, expr); @@ -77,7 +77,6 @@ impl<'a, 'gcx, 'tcx> Visitor<'gcx> for InferBorrowKindVisitor<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { fn analyze_closure( &self, - closure_node_id: ast::NodeId, closure_hir_id: hir::HirId, span: Span, body: &hir::Body, @@ -89,7 +88,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { debug!( "analyze_closure(id={:?}, body.id={:?})", - closure_node_id, + closure_hir_id, body.id() ); @@ -105,7 +104,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { span_bug!( span, "type of closure expr {:?} is not a closure {:?}", - closure_node_id, + closure_hir_id, t ); } @@ -121,6 +120,8 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> { None }; + let closure_node_id = self.tcx.hir().hir_to_node_id(closure_hir_id); + self.tcx.with_freevars(closure_node_id, |freevars| { let mut freevar_list: Vec = Vec::with_capacity(freevars.len()); for freevar in freevars { @@ -582,7 +583,7 @@ impl<'a, 'gcx, 'tcx> InferBorrowKind<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { fn consume( &mut self, - _consume_id: ast::NodeId, + _consume_id: hir::HirId, _consume_span: Span, cmt: &mc::cmt_<'tcx>, mode: euv::ConsumeMode, @@ -611,7 +612,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { fn borrow( &mut self, - borrow_id: ast::NodeId, + borrow_id: hir::HirId, _borrow_span: Span, cmt: &mc::cmt_<'tcx>, _loan_region: ty::Region<'tcx>, @@ -638,7 +639,7 @@ impl<'a, 'gcx, 'tcx> euv::Delegate<'tcx> for InferBorrowKind<'a, 'gcx, 'tcx> { fn mutate( &mut self, - _assignment_id: ast::NodeId, + _assignment_id: hir::HirId, _assignment_span: Span, assignee_cmt: &mc::cmt_<'tcx>, _mode: euv::MutateMode, diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 9217484f3a7af..69f2a17fdf11c 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -4,7 +4,7 @@ use crate::constrained_type_params::{identify_constrained_type_params, Parameter use crate::hir::def_id::DefId; use rustc::traits::{self, ObligationCauseCode}; use rustc::ty::{self, Lift, Ty, TyCtxt, TyKind, GenericParamDefKind, TypeFoldable, ToPredicate}; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::util::nodemap::{FxHashSet, FxHashMap}; use rustc::middle::lang_items; use rustc::infer::opaque_types::may_define_existential_type; @@ -459,7 +459,7 @@ fn check_where_clauses<'a, 'gcx, 'fcx, 'tcx>( // For more examples see tests `defaults-well-formedness.rs` and `type-check-defaults.rs`. // // First we build the defaulted substitution. - let substs = Substs::for_item(fcx.tcx, def_id, |param, _| { + let substs = InternalSubsts::for_item(fcx.tcx, def_id, |param, _| { match param.kind { GenericParamDefKind::Lifetime => { // All regions are identity. diff --git a/src/librustc_typeck/check/writeback.rs b/src/librustc_typeck/check/writeback.rs index c4575e6b01ee5..7c1283a6d2108 100644 --- a/src/librustc_typeck/check/writeback.rs +++ b/src/librustc_typeck/check/writeback.rs @@ -243,11 +243,11 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> { } hir::ExprKind::Struct(_, ref fields, _) => { for field in fields { - self.visit_field_id(field.id); + self.visit_field_id(field.hir_id); } } hir::ExprKind::Field(..) => { - self.visit_field_id(e.id); + self.visit_field_id(e.hir_id); } _ => {} } @@ -273,7 +273,7 @@ impl<'cx, 'gcx, 'tcx> Visitor<'gcx> for WritebackCx<'cx, 'gcx, 'tcx> { } hir::PatKind::Struct(_, ref fields, _) => { for field in fields { - self.visit_field_id(field.node.id); + self.visit_field_id(field.node.hir_id); } } _ => {} @@ -590,8 +590,7 @@ impl<'cx, 'gcx, 'tcx> WritebackCx<'cx, 'gcx, 'tcx> { } } - fn visit_field_id(&mut self, node_id: ast::NodeId) { - let hir_id = self.tcx().hir().node_to_hir_id(node_id); + fn visit_field_id(&mut self, hir_id: hir::HirId) { if let Some(index) = self.fcx .tables .borrow_mut() diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 5af66969477ca..167fb109567d5 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -23,7 +23,7 @@ use crate::middle::resolve_lifetime as rl; use crate::middle::weak_lang_items; use rustc::mir::mono::Linkage; use rustc::ty::query::Providers; -use rustc::ty::subst::{Subst, Substs}; +use rustc::ty::subst::{Subst, InternalSubsts}; use rustc::ty::util::Discr; use rustc::ty::util::IntTypeExt; use rustc::ty::subst::UnpackedKind; @@ -129,12 +129,12 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { hir::GenericParamKind::Type { default: Some(_), .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); self.tcx.type_of(def_id); } hir::GenericParamKind::Type { .. } => {} hir::GenericParamKind::Const { .. } => { - let def_id = self.tcx.hir().local_def_id(param.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(param.hir_id); self.tcx.type_of(def_id); } } @@ -144,7 +144,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'a, 'tcx> { fn visit_expr(&mut self, expr: &'tcx hir::Expr) { if let hir::ExprKind::Closure(..) = expr.node { - let def_id = self.tcx.hir().local_def_id(expr.id); + let def_id = self.tcx.hir().local_def_id_from_hir_id(expr.hir_id); self.tcx.generics_of(def_id); self.tcx.type_of(def_id); } @@ -322,9 +322,10 @@ fn type_param_predicates<'a, 'tcx>( }; let icx = ItemCtxt::new(tcx, item_def_id); + let param_hir_id = tcx.hir().node_to_hir_id(param_id); Lrc::make_mut(&mut result) .predicates - .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_id, ty, + .extend(icx.type_parameter_bounds_in_generics(ast_generics, param_hir_id, ty, OnlySelfBounds(true))); result } @@ -337,7 +338,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { fn type_parameter_bounds_in_generics( &self, ast_generics: &hir::Generics, - param_id: ast::NodeId, + param_id: hir::HirId, ty: Ty<'tcx>, only_self_bounds: OnlySelfBounds, ) -> Vec<(ty::Predicate<'tcx>, Span)> { @@ -345,7 +346,7 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { .params .iter() .filter_map(|param| match param.kind { - GenericParamKind::Type { .. } if param.id == param_id => Some(¶m.bounds), + GenericParamKind::Type { .. } if param.hir_id == param_id => Some(¶m.bounds), _ => None, }) .flat_map(|bounds| bounds.iter()) @@ -382,12 +383,12 @@ impl<'a, 'tcx> ItemCtxt<'a, 'tcx> { fn is_param<'a, 'tcx>( tcx: TyCtxt<'a, 'tcx, 'tcx>, ast_ty: &hir::Ty, - param_id: ast::NodeId, + param_id: hir::HirId, ) -> bool { if let hir::TyKind::Path(hir::QPath::Resolved(None, ref path)) = ast_ty.node { match path.def { Def::SelfTy(Some(def_id), None) | Def::TyParam(def_id) => { - def_id == tcx.hir().local_def_id(param_id) + def_id == tcx.hir().local_def_id_from_hir_id(param_id) } _ => false, } @@ -721,7 +722,7 @@ fn super_predicates_of<'a, 'tcx>( // as one of its "superpredicates". let is_trait_alias = tcx.is_trait_alias(trait_def_id); let superbounds2 = icx.type_parameter_bounds_in_generics( - generics, item.id, self_param_ty, OnlySelfBounds(!is_trait_alias)); + generics, item.hir_id, self_param_ty, OnlySelfBounds(!is_trait_alias)); // Combine the two lists to form the complete set of superbounds: let superbounds: Vec<_> = superbounds1.into_iter().chain(superbounds2).collect(); @@ -987,7 +988,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty .map(|(i, param)| ty::GenericParamDef { name: param.name.ident().as_interned_str(), index: own_start + i as u32, - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Lifetime, }), @@ -1018,9 +1019,9 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty if !allow_defaults && default.is_some() { if !tcx.features().default_type_parameter_fallback { - tcx.lint_node( + tcx.lint_hir( lint::builtin::INVALID_TYPE_PARAM_DEFAULT, - param.id, + param.hir_id, param.span, &format!( "defaults for type parameters are only allowed in \ @@ -1033,7 +1034,7 @@ fn generics_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx ty let ty_param = ty::GenericParamDef { index: type_start + i as u32, name: param.name.ident().as_interned_str(), - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), pure_wrt_drop: param.pure_wrt_drop, kind: ty::GenericParamDefKind::Type { has_default: default.is_some(), @@ -1148,7 +1149,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { match tcx.hir().get(node_id) { Node::TraitItem(item) => match item.node { TraitItemKind::Method(..) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } TraitItemKind::Const(ref ty, _) | TraitItemKind::Type(_, Some(ref ty)) => icx.to_ty(ty), @@ -1159,7 +1160,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { Node::ImplItem(item) => match item.node { ImplItemKind::Method(..) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } ImplItemKind::Const(ref ty, _) => icx.to_ty(ty), @@ -1192,12 +1193,12 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { | ItemKind::Ty(ref t, _) | ItemKind::Impl(.., ref t, _) => icx.to_ty(t), ItemKind::Fn(..) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { let def = tcx.adt_def(def_id); - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_adt(def, substs) } ItemKind::Existential(hir::ExistTy { @@ -1245,7 +1246,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { Node::ForeignItem(foreign_item) => match foreign_item.node { ForeignItemKind::Fn(..) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } ForeignItemKind::Static(ref t, _) => icx.to_ty(t), @@ -1261,7 +1262,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { tcx.type_of(tcx.hir().get_parent_did(node_id)) } VariantData::Tuple(..) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); tcx.mk_fn_def(def_id, substs) } }, @@ -1278,7 +1279,7 @@ fn type_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Ty<'tcx> { } let substs = ty::ClosureSubsts { - substs: Substs::identity_for_item(tcx, def_id), + substs: InternalSubsts::identity_for_item(tcx, def_id), }; tcx.mk_closure(def_id, substs) @@ -1704,8 +1705,7 @@ fn early_bound_lifetimes_from_generics<'a, 'tcx>( .iter() .filter(move |param| match param.kind { GenericParamKind::Lifetime { .. } => { - let hir_id = tcx.hir().node_to_hir_id(param.id); - !tcx.is_late_bound(hir_id) + !tcx.is_late_bound(param.hir_id) } _ => false, }) @@ -1829,7 +1829,7 @@ fn explicit_predicates_of<'a, 'tcx>( Node::ImplItem(item) => match item.node { ImplItemKind::Existential(ref bounds) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); let opaque_ty = tcx.mk_opaque(def_id, substs); // Collect the bounds, i.e., the `A+B+'c` in `impl A+B+'c`. @@ -1874,7 +1874,7 @@ fn explicit_predicates_of<'a, 'tcx>( impl_trait_fn, ref generics, }) => { - let substs = Substs::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id); let opaque_ty = tcx.mk_opaque(def_id, substs); // Collect the bounds, i.e., the `A+B+'c` in `impl A+B+'c`. @@ -1942,7 +1942,7 @@ fn explicit_predicates_of<'a, 'tcx>( let mut index = parent_count + has_own_self as u32; for param in early_bound_lifetimes_from_generics(tcx, ast_generics) { let region = tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion { - def_id: tcx.hir().local_def_id(param.id), + def_id: tcx.hir().local_def_id_from_hir_id(param.hir_id), index, name: param.name.ident().as_interned_str(), })); @@ -2224,7 +2224,7 @@ fn compute_sig_of_foreign_fn_decl<'a, 'tcx>( &format!( "use of SIMD type `{}` in FFI is highly experimental and \ may result in invalid code", - tcx.hir().node_to_pretty_string(ast_ty.id) + tcx.hir().hir_to_pretty_string(ast_ty.hir_id) ), ) .help("add #![feature(simd_ffi)] to the crate attributes to enable") diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 3682acd3c62c1..2095c81d0fb0d 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -105,7 +105,7 @@ use rustc::session; use rustc::session::CompileIncomplete; use rustc::session::config::{EntryFnType, nightly_options}; use rustc::traits::{ObligationCause, ObligationCauseCode, TraitEngine, TraitEngineExt}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::SubstsRef; use rustc::ty::{self, Ty, TyCtxt}; use rustc::ty::query::Providers; use rustc::util; @@ -116,7 +116,7 @@ use util::common::time; use std::iter; pub struct TypeAndSubsts<'tcx> { - substs: &'tcx Substs<'tcx>, + substs: SubstsRef<'tcx>, ty: Ty<'tcx>, } @@ -136,14 +136,14 @@ fn check_type_alias_enum_variants_enabled<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, } } -fn require_c_abi_if_variadic(tcx: TyCtxt<'_, '_, '_>, - decl: &hir::FnDecl, - abi: Abi, - span: Span) { - if decl.variadic && !(abi == Abi::C || abi == Abi::Cdecl) { +fn require_c_abi_if_c_variadic(tcx: TyCtxt<'_, '_, '_>, + decl: &hir::FnDecl, + abi: Abi, + span: Span) { + if decl.c_variadic && !(abi == Abi::C || abi == Abi::Cdecl) { let mut err = struct_span_err!(tcx.sess, span, E0045, - "variadic function must have C or cdecl calling convention"); - err.span_label(span, "variadics require C or cdecl calling convention").emit(); + "C-variadic function must have C or cdecl calling convention"); + err.span_label(span, "C-variadics require C or cdecl calling convention").emit(); } } @@ -371,8 +371,8 @@ pub fn hir_ty_to_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, hir_ty: &hir::Ty) -> // In case there are any projections etc, find the "environment" // def-id that will be used to determine the traits/predicates in // scope. This is derived from the enclosing item-like thing. - let env_node_id = tcx.hir().get_parent(hir_ty.id); - let env_def_id = tcx.hir().local_def_id(env_node_id); + let env_node_id = tcx.hir().get_parent_item(hir_ty.hir_id); + let env_def_id = tcx.hir().local_def_id_from_hir_id(env_node_id); let item_cx = self::collect::ItemCtxt::new(tcx, env_def_id); astconv::AstConv::ast_ty_to_ty(&item_cx, hir_ty) diff --git a/src/librustc_typeck/variance/constraints.rs b/src/librustc_typeck/variance/constraints.rs index 1d407870ee73a..7b94b047c92e2 100644 --- a/src/librustc_typeck/variance/constraints.rs +++ b/src/librustc_typeck/variance/constraints.rs @@ -4,7 +4,7 @@ //! We walk the set of items and, for each member, generate new constraints. use hir::def_id::DefId; -use rustc::ty::subst::{Substs, UnpackedKind}; +use rustc::ty::subst::{UnpackedKind, SubstsRef}; use rustc::ty::{self, Ty, TyCtxt}; use syntax::ast; use rustc::hir; @@ -222,7 +222,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { fn add_constraints_from_invariant_substs(&mut self, current: &CurrentItem, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, variance: VarianceTermPtr<'a>) { debug!("add_constraints_from_invariant_substs: substs={:?} variance={:?}", substs, @@ -344,7 +344,7 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> { fn add_constraints_from_substs(&mut self, current: &CurrentItem, def_id: DefId, - substs: &Substs<'tcx>, + substs: SubstsRef<'tcx>, variance: VarianceTermPtr<'a>) { debug!("add_constraints_from_substs(def_id={:?}, substs={:?}, variance={:?})", def_id, diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 03dff10877041..53dcc258c690b 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -20,7 +20,7 @@ use rustc::mir::interpret::GlobalId; use rustc::hir::{self, GenericArg, HirVec}; use rustc::hir::def::{self, Def, CtorKind}; use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE}; -use rustc::ty::subst::Substs; +use rustc::ty::subst::{InternalSubsts, SubstsRef}; use rustc::ty::{self, TyCtxt, Region, RegionVid, Ty, AdtKind}; use rustc::ty::fold::TypeFolder; use rustc::ty::layout::VariantIdx; @@ -1089,7 +1089,7 @@ impl Clean for hir::GenericBound { } fn external_generic_args(cx: &DocContext<'_, '_, '_>, trait_did: Option, has_self: bool, - bindings: Vec, substs: &Substs<'_>) -> GenericArgs { + bindings: Vec, substs: SubstsRef<'_>) -> GenericArgs { let lifetimes = substs.regions().filter_map(|v| v.clean(cx)).collect(); let types = substs.types().skip(has_self as usize).collect::>(); @@ -1131,7 +1131,7 @@ fn external_generic_args(cx: &DocContext<'_, '_, '_>, trait_did: Option, // trait_did should be set to a trait's DefId if called on a TraitRef, in order to sugar // from Fn<(A, B,), C> to Fn(A, B) -> C fn external_path(cx: &DocContext<'_, '_, '_>, name: &str, trait_did: Option, has_self: bool, - bindings: Vec, substs: &Substs<'_>) -> Path { + bindings: Vec, substs: SubstsRef<'_>) -> Path { Path { global: false, def: Def::Err, @@ -1192,7 +1192,7 @@ impl<'tcx> Clean for ty::TraitRef<'tcx> { } } -impl<'tcx> Clean>> for Substs<'tcx> { +impl<'tcx> Clean>> for InternalSubsts<'tcx> { fn clean(&self, cx: &DocContext<'_, '_, '_>) -> Option> { let mut v = Vec::new(); v.extend(self.regions().filter_map(|r| r.clean(cx)).map(GenericBound::Outlives)); @@ -1221,7 +1221,7 @@ impl Lifetime { impl Clean for hir::Lifetime { fn clean(&self, cx: &DocContext<'_, '_, '_>) -> Lifetime { - if self.id != ast::DUMMY_NODE_ID { + if self.hir_id != hir::DUMMY_HIR_ID { let def = cx.tcx.named_region(self.hir_id); match def { Some(rl::Region::EarlyBound(_, node_id, _)) | @@ -1513,7 +1513,7 @@ impl Clean for hir::GenericParam { } hir::GenericParamKind::Type { ref default, synthetic } => { (self.name.ident().name.clean(cx), GenericParamDefKind::Type { - did: cx.tcx.hir().local_def_id(self.id), + did: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), bounds: self.bounds.clean(cx), default: default.clean(cx), synthetic: synthetic, @@ -1521,7 +1521,7 @@ impl Clean for hir::GenericParam { } hir::GenericParamKind::Const { ref ty } => { (self.name.ident().name.clean(cx), GenericParamDefKind::Const { - did: cx.tcx.hir().local_def_id(self.id), + did: cx.tcx.hir().local_def_id_from_hir_id(self.hir_id), ty: ty.clean(cx), }) } @@ -1752,7 +1752,6 @@ impl Clean for doctree::Function { pub struct FnDecl { pub inputs: Arguments, pub output: FunctionRetTy, - pub variadic: bool, pub attrs: Attributes, } @@ -1831,7 +1830,6 @@ 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), - variadic: self.0.variadic, attrs: Attributes::default() } } @@ -1849,7 +1847,6 @@ impl<'a, 'tcx> Clean for (DefId, ty::PolyFnSig<'tcx>) { FnDecl { output: Return(sig.skip_binder().output().clean(cx)), attrs: Attributes::default(), - variadic: sig.skip_binder().variadic, inputs: Arguments { values: sig.skip_binder().inputs().iter().map(|t| { Argument { @@ -1988,7 +1985,7 @@ impl Clean for hir::IsAuto { impl Clean for hir::TraitRef { fn clean(&self, cx: &DocContext<'_, '_, '_>) -> Type { - resolve_type(cx, self.path.clean(cx), self.ref_id) + resolve_type(cx, self.path.clean(cx), self.hir_ref_id) } } @@ -2252,6 +2249,7 @@ pub enum Type { Slice(Box), Array(Box, String), Never, + CVarArgs, Unique(Box), RawPointer(Mutability, Box), BorrowedRef { @@ -2290,6 +2288,7 @@ pub enum PrimitiveType { Reference, Fn, Never, + CVarArgs, } #[derive(Clone, RustcEncodable, RustcDecodable, Copy, Debug)] @@ -2469,6 +2468,7 @@ impl PrimitiveType { Reference => "reference", Fn => "fn", Never => "never", + CVarArgs => "...", } } @@ -2518,6 +2518,7 @@ impl Clean for hir::Ty { match self.node { TyKind::Never => Never, + TyKind::CVarArgs(_) => CVarArgs, TyKind::Ptr(ref m) => RawPointer(m.mutbl.clean(cx), box m.ty.clean(cx)), TyKind::Rptr(ref l, ref m) => { let lifetime = if l.is_elided() { @@ -2532,7 +2533,7 @@ impl Clean for hir::Ty { TyKind::Array(ref ty, ref length) => { let def_id = cx.tcx.hir().local_def_id(length.id); let param_env = cx.tcx.param_env(def_id); - let substs = Substs::identity_for_item(cx.tcx, def_id); + let substs = InternalSubsts::identity_for_item(cx.tcx, def_id); let cid = GlobalId { instance: ty::Instance::new(def_id, substs), promoted: None @@ -2599,7 +2600,7 @@ impl Clean for hir::Ty { if let Some(lt) = lifetime.cloned() { if !lt.is_elided() { let lt_def_id = - cx.tcx.hir().local_def_id(param.id); + cx.tcx.hir().local_def_id_from_hir_id(param.hir_id); lt_substs.insert(lt_def_id, lt.clean(cx)); } } @@ -2607,7 +2608,8 @@ impl Clean for hir::Ty { } hir::GenericParamKind::Type { ref default, .. } => { let ty_param_def = - Def::TyParam(cx.tcx.hir().local_def_id(param.id)); + Def::TyParam( + cx.tcx.hir().local_def_id_from_hir_id(param.hir_id)); let mut j = 0; let type_ = generic_args.args.iter().find_map(|arg| { match arg { @@ -2631,7 +2633,8 @@ impl Clean for hir::Ty { } hir::GenericParamKind::Const { .. } => { let const_param_def = - Def::ConstParam(cx.tcx.hir().local_def_id(param.id)); + Def::ConstParam( + cx.tcx.hir().local_def_id_from_hir_id(param.hir_id)); let mut j = 0; let const_ = generic_args.args.iter().find_map(|arg| { match arg { @@ -2656,7 +2659,7 @@ impl Clean for hir::Ty { }); return cx.enter_alias(ty_substs, lt_substs, const_substs, || ty.clean(cx)); } - resolve_type(cx, path.clean(cx), self.id) + resolve_type(cx, path.clean(cx), self.hir_id) } TyKind::Path(hir::QPath::Resolved(Some(ref qself), ref p)) => { let mut segments: Vec<_> = p.segments.clone().into(); @@ -2669,7 +2672,7 @@ impl Clean for hir::Ty { Type::QPath { name: p.segments.last().expect("segments were empty").ident.name.clean(cx), self_type: box qself.clean(cx), - trait_: box resolve_type(cx, trait_path.clean(cx), self.id) + trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id) } } TyKind::Path(hir::QPath::TypeRelative(ref qself, ref segment)) => { @@ -2686,7 +2689,7 @@ impl Clean for hir::Ty { Type::QPath { name: segment.ident.name.clean(cx), self_type: box qself.clean(cx), - trait_: box resolve_type(cx, trait_path.clean(cx), self.id) + trait_: box resolve_type(cx, trait_path.clean(cx), self.hir_id) } } TyKind::TraitObject(ref bounds, ref lifetime) => { @@ -2774,7 +2777,7 @@ impl<'tcx> Clean for Ty<'tcx> { ty::Foreign(did) => { inline::record_extern_fqn(cx, did, TypeKind::Foreign); let path = external_path(cx, &cx.tcx.item_name(did).as_str(), - None, false, vec![], Substs::empty()); + None, false, vec![], InternalSubsts::empty()); ResolvedPath { path: path, typarams: None, @@ -3652,6 +3655,7 @@ 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() { @@ -3909,8 +3913,8 @@ fn print_const_expr(cx: &DocContext<'_, '_, '_>, body: hir::BodyId) -> String { /// Given a type Path, resolve it to a Type using the TyCtxt fn resolve_type(cx: &DocContext<'_, '_, '_>, path: Path, - id: ast::NodeId) -> Type { - if id == ast::DUMMY_NODE_ID { + id: hir::HirId) -> Type { + if id == hir::DUMMY_HIR_ID { debug!("resolve_type({:?})", path); } else { debug!("resolve_type({:?},{:?})", path, id); diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 4f70751c90537..226924c41c541 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -193,7 +193,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { }; hir::Ty { - id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved(None, P(new_path))), span: DUMMY_SP, hir_id: hir::DUMMY_HIR_ID, @@ -213,7 +212,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { }; args.push(hir::GenericArg::Lifetime(hir::Lifetime { - id: ast::DUMMY_NODE_ID, hir_id: hir::DUMMY_HIR_ID, span: DUMMY_SP, name: hir::LifetimeName::Param(name), @@ -235,7 +233,6 @@ impl<'a, 'tcx, 'rcx> DocContext<'a, 'tcx, 'rcx> { pub fn ty_param_to_ty(&self, param: ty::GenericParamDef) -> hir::Ty { debug!("ty_param_to_ty({:?}) {:?}", param, param.def_id); hir::Ty { - id: ast::DUMMY_NODE_ID, node: hir::TyKind::Path(hir::QPath::Resolved( None, P(hir::Path { diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 4463dad1c8a1f..d204a179ca62c 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -609,6 +609,7 @@ 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) => { match **t { clean::Generic(_) | clean::ResolvedPath {is_generic: true, ..} => { @@ -834,18 +835,10 @@ impl fmt::Display for clean::FunctionRetTy { impl fmt::Display for clean::FnDecl { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - if self.variadic { - if f.alternate() { - write!(f, "({args:#}, ...){arrow:#}", args = self.inputs, arrow = self.output) - } else { - write!(f, "({args}, ...){arrow}", args = self.inputs, arrow = self.output) - } + if f.alternate() { + write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output) } else { - if f.alternate() { - write!(f, "({args:#}){arrow:#}", args = self.inputs, arrow = self.output) - } else { - write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output) - } + write!(f, "({args}){arrow}", args = self.inputs, arrow = self.output) } } } @@ -907,12 +900,7 @@ impl<'a> fmt::Display for Function<'a> { } } - let mut args_plain = format!("({})", args_plain); - - if decl.variadic { - args.push_str(",
..."); - args_plain.push_str(", ..."); - } + let args_plain = format!("({})", args_plain); let output = if let hir::IsAsync::Async = asyncness { Cow::Owned(decl.sugared_async_return_type()) diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index 3db65205a2dc4..8dad26f9292cd 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -868,7 +868,7 @@ impl<'a, 'hir> intravisit::Visitor<'hir> for HirCollector<'a, 'hir> { fn visit_item(&mut self, item: &'hir hir::Item) { let name = if let hir::ItemKind::Impl(.., ref ty, _) = item.node { - self.map.node_to_pretty_string(ty.id) + self.map.hir_to_pretty_string(ty.hir_id) } else { item.ident.to_string() }; diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index 2428a823d0b39..b791bfc11e01a 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -66,13 +66,13 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } } - fn stability(&self, id: ast::NodeId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) + fn stability(&self, id: hir::HirId) -> Option { + self.cx.tcx.hir().opt_local_def_id_from_hir_id(id) .and_then(|def_id| self.cx.tcx.lookup_stability(def_id)).cloned() } - fn deprecation(&self, id: ast::NodeId) -> Option { - self.cx.tcx.hir().opt_local_def_id(id) + fn deprecation(&self, id: hir::HirId) -> Option { + self.cx.tcx.hir().opt_local_def_id_from_hir_id(id) .and_then(|def_id| self.cx.tcx.lookup_deprecation(def_id)) } @@ -83,7 +83,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { krate.attrs.clone(), Spanned { span: syntax_pos::DUMMY_SP, node: hir::VisibilityKind::Public }, - ast::CRATE_NODE_ID, + hir::CRATE_HIR_ID, &krate.module, None); // Attach the crate's exported macros to the top-level module: @@ -105,8 +105,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { struct_type, name, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), generics: generics.clone(), fields: sd.fields().iter().cloned().collect(), @@ -124,8 +124,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { struct_type, name, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), generics: generics.clone(), fields: sd.fields().iter().cloned().collect(), @@ -142,14 +142,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { variants: def.variants.iter().map(|v| Variant { name: v.node.ident.name, attrs: v.node.attrs.clone(), - stab: self.stability(v.node.data.id()), - depr: self.deprecation(v.node.data.id()), + stab: self.stability(v.node.data.hir_id()), + depr: self.deprecation(v.node.data.hir_id()), def: v.node.data.clone(), whence: v.span, }).collect(), vis: it.vis.clone(), - stab: self.stability(it.id), - depr: self.deprecation(it.id), + stab: self.stability(it.hir_id), + depr: self.deprecation(it.hir_id), generics: params.clone(), attrs: it.attrs.clone(), id: it.id, @@ -207,16 +207,16 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { helpers, attrs: item.attrs.clone(), whence: item.span, - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }); } None => { om.fns.push(Function { id: item.id, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), attrs: item.attrs.clone(), decl: fd.clone(), name, @@ -230,7 +230,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { } pub fn visit_mod_contents(&mut self, span: Span, attrs: hir::HirVec, - vis: hir::Visibility, id: ast::NodeId, + vis: hir::Visibility, id: hir::HirId, m: &hir::Mod, name: Option) -> Module { let mut om = Module::new(name); @@ -240,7 +240,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.vis = vis.clone(); om.stab = self.stability(id); om.depr = self.deprecation(id); - om.id = id; + om.id = self.cx.tcx.hir().hir_to_node_id(id); // Keep track of if there were any private modules in the path. let orig_inside_public_path = self.inside_public_path; self.inside_public_path &= vis.node.is_pub(); @@ -460,7 +460,7 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { om.mods.push(self.visit_mod_contents(item.span, item.attrs.clone(), item.vis.clone(), - item.id, + item.hir_id, m, Some(ident.name))); }, @@ -481,8 +481,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.typedefs.push(t); }, @@ -494,8 +494,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.existentials.push(t); }, @@ -509,8 +509,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.statics.push(s); }, @@ -523,8 +523,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.constants.push(s); }, @@ -543,8 +543,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.traits.push(t); }, @@ -557,8 +557,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { attrs: item.attrs.clone(), whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.trait_aliases.push(t); }, @@ -588,8 +588,8 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { id: item.id, whence: item.span, vis: item.vis.clone(), - stab: self.stability(item.id), - depr: self.deprecation(item.id), + stab: self.stability(item.hir_id), + depr: self.deprecation(item.hir_id), }; om.impls.push(i); } @@ -609,13 +609,14 @@ impl<'a, 'tcx, 'rcx> RustdocVisitor<'a, 'tcx, 'rcx> { let matchers = tts.chunks(4).map(|arm| arm[0].span()).collect(); Macro { - def_id: self.cx.tcx.hir().local_def_id(def.id), + + def_id: self.cx.tcx.hir().local_def_id_from_hir_id(def.hir_id), attrs: def.attrs.clone(), name: renamed.unwrap_or(def.name), whence: def.span, matchers, - stab: self.stability(def.id), - depr: self.deprecation(def.id), + stab: self.stability(def.hir_id), + depr: self.deprecation(def.hir_id), imported_from: None, } } diff --git a/src/libstd/error.rs b/src/libstd/error.rs index ef8c97bebdffd..17e50a649fa52 100644 --- a/src/libstd/error.rs +++ b/src/libstd/error.rs @@ -466,14 +466,14 @@ impl Error for num::ParseIntError { } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl Error for num::TryFromIntError { fn description(&self) -> &str { self.__description() } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl Error for array::TryFromSliceError { fn description(&self) -> &str { self.__description() @@ -548,7 +548,7 @@ impl Error for cell::BorrowMutError { } } -#[unstable(feature = "try_from", issue = "33417")] +#[stable(feature = "try_from", since = "1.34.0")] impl Error for char::CharTryFromError { fn description(&self) -> &str { "converted integer out of range for `char`" diff --git a/src/libstd/io/buffered.rs b/src/libstd/io/buffered.rs index 0c1d155a91688..6383a14cf184c 100644 --- a/src/libstd/io/buffered.rs +++ b/src/libstd/io/buffered.rs @@ -5,7 +5,7 @@ use io::prelude::*; use cmp; use error; use fmt; -use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom}; +use io::{self, Initializer, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom, IoVec, IoVecMut}; use memchr; /// The `BufReader` struct adds buffering to any reader. @@ -235,6 +235,19 @@ impl Read for BufReader { Ok(nread) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum::(); + if self.pos == self.cap && total_len >= self.buf.len() { + return self.inner.read_vectored(bufs); + } + let nread = { + let mut rem = self.fill_buf()?; + rem.read_vectored(bufs)? + }; + self.consume(nread); + Ok(nread) + } + // we can't skip unconditionally because of the large buffer case in read. unsafe fn initializer(&self) -> Initializer { self.inner.initializer() @@ -577,9 +590,25 @@ impl Write for BufWriter { self.panicked = false; r } else { - Write::write(&mut self.buf, buf) + self.buf.write(buf) + } + } + + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum::(); + if self.buf.len() + total_len > self.buf.capacity() { + self.flush_buf()?; + } + if total_len >= self.buf.capacity() { + self.panicked = true; + let r = self.inner.as_mut().unwrap().write_vectored(bufs); + self.panicked = false; + r + } else { + self.buf.write_vectored(bufs) } } + fn flush(&mut self) -> io::Result<()> { self.flush_buf().and_then(|()| self.get_mut().flush()) } diff --git a/src/libstd/io/cursor.rs b/src/libstd/io/cursor.rs index 758d856867291..577a115025ba7 100644 --- a/src/libstd/io/cursor.rs +++ b/src/libstd/io/cursor.rs @@ -2,7 +2,7 @@ use io::prelude::*; use core::convert::TryInto; use cmp; -use io::{self, Initializer, SeekFrom, Error, ErrorKind}; +use io::{self, Initializer, SeekFrom, Error, ErrorKind, IoVec, IoVecMut}; /// A `Cursor` wraps an in-memory buffer and provides it with a /// [`Seek`] implementation. @@ -221,6 +221,18 @@ impl Read for Cursor where T: AsRef<[u8]> { Ok(n) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { + let n = self.read(buf)?; + nread += n; + if n < buf.len() { + break; + } + } + Ok(nread) + } + fn read_exact(&mut self, buf: &mut [u8]) -> io::Result<()> { let n = buf.len(); Read::read_exact(&mut self.fill_buf()?, buf)?; @@ -251,6 +263,23 @@ fn slice_write(pos_mut: &mut u64, slice: &mut [u8], buf: &[u8]) -> io::Result], +) -> io::Result +{ + let mut nwritten = 0; + for buf in bufs { + let n = slice_write(pos_mut, slice, buf)?; + nwritten += n; + if n < buf.len() { + break; + } + } + Ok(nwritten) +} + // Resizing write implementation fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result { let pos: usize = (*pos_mut).try_into().map_err(|_| { @@ -278,12 +307,31 @@ fn vec_write(pos_mut: &mut u64, vec: &mut Vec, buf: &[u8]) -> io::Result, + bufs: &[IoVec<'_>], +) -> io::Result +{ + let mut nwritten = 0; + for buf in bufs { + nwritten += vec_write(pos_mut, vec, buf)?; + } + Ok(nwritten) +} + #[stable(feature = "rust1", since = "1.0.0")] impl Write for Cursor<&mut [u8]> { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { slice_write(&mut self.pos, self.inner, buf) } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, self.inner, bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -292,6 +340,11 @@ impl Write for Cursor<&mut Vec> { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, self.inner, buf) } + + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, self.inner, bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -300,6 +353,11 @@ impl Write for Cursor> { fn write(&mut self, buf: &[u8]) -> io::Result { vec_write(&mut self.pos, &mut self.inner, buf) } + + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + vec_write_vectored(&mut self.pos, &mut self.inner, bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -309,13 +367,19 @@ impl Write for Cursor> { fn write(&mut self, buf: &[u8]) -> io::Result { slice_write(&mut self.pos, &mut self.inner, buf) } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + slice_write_vectored(&mut self.pos, &mut self.inner, bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } #[cfg(test)] mod tests { use io::prelude::*; - use io::{Cursor, SeekFrom}; + use io::{Cursor, SeekFrom, IoVec, IoVecMut}; #[test] fn test_vec_writer() { @@ -323,7 +387,10 @@ mod tests { assert_eq!(writer.write(&[0]).unwrap(), 1); assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); - let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; + assert_eq!(writer.write_vectored( + &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + ).unwrap(), 3); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(writer, b); } @@ -333,7 +400,10 @@ mod tests { assert_eq!(writer.write(&[0]).unwrap(), 1); assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); - let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; + assert_eq!(writer.write_vectored( + &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + ).unwrap(), 3); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(&writer.get_ref()[..], b); } @@ -344,7 +414,10 @@ mod tests { assert_eq!(writer.write(&[0]).unwrap(), 1); assert_eq!(writer.write(&[1, 2, 3]).unwrap(), 3); assert_eq!(writer.write(&[4, 5, 6, 7]).unwrap(), 4); - let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7]; + assert_eq!(writer.write_vectored( + &[IoVec::new(&[]), IoVec::new(&[8, 9]), IoVec::new(&[10])], + ).unwrap(), 3); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; assert_eq!(&writer.get_ref()[..], b); } @@ -366,6 +439,26 @@ mod tests { assert_eq!(&**writer.get_ref(), b); } + #[test] + fn test_box_slice_writer_vectored() { + let mut writer = Cursor::new(vec![0u8; 9].into_boxed_slice()); + assert_eq!(writer.position(), 0); + assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1); + assert_eq!(writer.position(), 1); + assert_eq!( + writer.write_vectored(&[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])]).unwrap(), + 7, + ); + assert_eq!(writer.position(), 8); + assert_eq!(writer.write_vectored(&[]).unwrap(), 0); + assert_eq!(writer.position(), 8); + + assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0); + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; + assert_eq!(&**writer.get_ref(), b); + } + #[test] fn test_buf_writer() { let mut buf = [0 as u8; 9]; @@ -387,6 +480,31 @@ mod tests { assert_eq!(buf, b); } + #[test] + fn test_buf_writer_vectored() { + let mut buf = [0 as u8; 9]; + { + let mut writer = Cursor::new(&mut buf[..]); + assert_eq!(writer.position(), 0); + assert_eq!(writer.write_vectored(&[IoVec::new(&[0])]).unwrap(), 1); + assert_eq!(writer.position(), 1); + assert_eq!( + writer.write_vectored( + &[IoVec::new(&[1, 2, 3]), IoVec::new(&[4, 5, 6, 7])], + ).unwrap(), + 7, + ); + assert_eq!(writer.position(), 8); + assert_eq!(writer.write_vectored(&[]).unwrap(), 0); + assert_eq!(writer.position(), 8); + + assert_eq!(writer.write_vectored(&[IoVec::new(&[8, 9])]).unwrap(), 1); + assert_eq!(writer.write_vectored(&[IoVec::new(&[10])]).unwrap(), 0); + } + let b: &[_] = &[0, 1, 2, 3, 4, 5, 6, 7, 8]; + assert_eq!(buf, b); + } + #[test] fn test_buf_writer_seek() { let mut buf = [0 as u8; 8]; @@ -447,6 +565,35 @@ mod tests { assert_eq!(reader.read(&mut buf).unwrap(), 0); } + #[test] + fn test_mem_reader_vectored() { + let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7]); + let mut buf = []; + assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + assert_eq!(reader.position(), 0); + let mut buf = [0]; + assert_eq!( + reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + 1, + ); + assert_eq!(reader.position(), 1); + let b: &[_] = &[0]; + assert_eq!(buf, b); + let mut buf1 = [0; 4]; + let mut buf2 = [0; 4]; + assert_eq!( + reader.read_vectored( + &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + ).unwrap(), + 7, + ); + let b1: &[_] = &[1, 2, 3, 4]; + let b2: &[_] = &[5, 6, 7]; + assert_eq!(buf1, b1); + assert_eq!(&buf2[..3], b2); + assert_eq!(reader.read(&mut buf).unwrap(), 0); + } + #[test] fn test_boxed_slice_reader() { let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7].into_boxed_slice()); @@ -469,6 +616,35 @@ mod tests { assert_eq!(reader.read(&mut buf).unwrap(), 0); } + #[test] + fn test_boxed_slice_reader_vectored() { + let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7].into_boxed_slice()); + let mut buf = []; + assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + assert_eq!(reader.position(), 0); + let mut buf = [0]; + assert_eq!( + reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + 1, + ); + assert_eq!(reader.position(), 1); + let b: &[_] = &[0]; + assert_eq!(buf, b); + let mut buf1 = [0; 4]; + let mut buf2 = [0; 4]; + assert_eq!( + reader.read_vectored( + &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + ).unwrap(), + 7, + ); + let b1: &[_] = &[1, 2, 3, 4]; + let b2: &[_] = &[5, 6, 7]; + assert_eq!(buf1, b1); + assert_eq!(&buf2[..3], b2); + assert_eq!(reader.read(&mut buf).unwrap(), 0); + } + #[test] fn read_to_end() { let mut reader = Cursor::new(vec![0, 1, 2, 3, 4, 5, 6, 7]); @@ -499,6 +675,35 @@ mod tests { assert_eq!(reader.read(&mut buf).unwrap(), 0); } + #[test] + fn test_slice_reader_vectored() { + let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; + let reader = &mut &in_buf[..]; + let mut buf = []; + assert_eq!(reader.read_vectored(&mut [IoVecMut::new(&mut buf)]).unwrap(), 0); + let mut buf = [0]; + assert_eq!( + reader.read_vectored(&mut [IoVecMut::new(&mut []), IoVecMut::new(&mut buf)]).unwrap(), + 1, + ); + assert_eq!(reader.len(), 7); + let b: &[_] = &[0]; + assert_eq!(buf, b); + let mut buf1 = [0; 4]; + let mut buf2 = [0; 4]; + assert_eq!( + reader.read_vectored( + &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + ).unwrap(), + 7, + ); + let b1: &[_] = &[1, 2, 3, 4]; + let b2: &[_] = &[5, 6, 7]; + assert_eq!(buf1, b1); + assert_eq!(&buf2[..3], b2); + assert_eq!(reader.read(&mut buf).unwrap(), 0); + } + #[test] fn test_read_exact() { let in_buf = vec![0, 1, 2, 3, 4, 5, 6, 7]; diff --git a/src/libstd/io/impls.rs b/src/libstd/io/impls.rs index 2577b284714ab..aa8db177ffcd1 100644 --- a/src/libstd/io/impls.rs +++ b/src/libstd/io/impls.rs @@ -1,5 +1,6 @@ use cmp; -use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind}; +use io::{self, SeekFrom, Read, Initializer, Write, Seek, BufRead, Error, ErrorKind, IoVecMut, + IoVec}; use fmt; use mem; @@ -13,6 +14,11 @@ impl Read for &mut R { (**self).read(buf) } + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { (**self).initializer() @@ -38,6 +44,11 @@ impl Write for &mut W { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) + } + #[inline] fn flush(&mut self) -> io::Result<()> { (**self).flush() } @@ -82,6 +93,11 @@ impl Read for Box { (**self).read(buf) } + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + (**self).read_vectored(bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { (**self).initializer() @@ -107,6 +123,11 @@ impl Write for Box { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { (**self).write(buf) } + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + (**self).write_vectored(bufs) + } + #[inline] fn flush(&mut self) -> io::Result<()> { (**self).flush() } @@ -171,6 +192,19 @@ impl Read for &[u8] { Ok(amt) } + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nread = 0; + for buf in bufs { + nread += self.read(buf)?; + if self.is_empty() { + break; + } + } + + Ok(nread) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -231,6 +265,19 @@ impl Write for &mut [u8] { Ok(amt) } + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let mut nwritten = 0; + for buf in bufs { + nwritten += self.write(buf)?; + if self.is_empty() { + break; + } + } + + Ok(nwritten) + } + #[inline] fn write_all(&mut self, data: &[u8]) -> io::Result<()> { if self.write(data)? == data.len() { @@ -254,6 +301,16 @@ impl Write for Vec { Ok(buf.len()) } + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let len = bufs.iter().map(|b| b.len()).sum(); + self.reserve(len); + for buf in bufs { + self.extend_from_slice(buf); + } + Ok(len) + } + #[inline] fn write_all(&mut self, buf: &[u8]) -> io::Result<()> { self.extend_from_slice(buf); diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs index b634ea43e34e5..12b158e4197fc 100644 --- a/src/libstd/io/mod.rs +++ b/src/libstd/io/mod.rs @@ -264,7 +264,9 @@ use fmt; use slice; use str; use memchr; +use ops::{Deref, DerefMut}; use ptr; +use sys; #[stable(feature = "rust1", since = "1.0.0")] pub use self::buffered::{BufReader, BufWriter, LineWriter}; @@ -520,6 +522,22 @@ pub trait Read { #[stable(feature = "rust1", since = "1.0.0")] fn read(&mut self, buf: &mut [u8]) -> Result; + /// Like `read`, except that it reads into a slice of buffers. + /// + /// Data is copied to fill each buffer in order, with the final buffer + /// written to possibly being only partially filled. This method must behave + /// as a single call to `read` with the buffers concatenated would. + /// + /// The default implementation simply passes the first nonempty buffer to + /// `read`. + #[unstable(feature = "iovec", issue = "58452")] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), + None => Ok(0), + } + } + /// Determines if this `Read`er can work with buffers of uninitialized /// memory. /// @@ -867,6 +885,92 @@ pub trait Read { } } +/// A buffer type used with `Read::read_vectored`. +/// +/// It is semantically a wrapper around an `&mut [u8]`, but is guaranteed to be +/// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on +/// Windows. +#[unstable(feature = "iovec", issue = "58452")] +#[repr(transparent)] +pub struct IoVecMut<'a>(sys::io::IoVecMut<'a>); + +#[unstable(feature = "iovec", issue = "58452")] +impl<'a> fmt::Debug for IoVecMut<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } +} + +impl<'a> IoVecMut<'a> { + /// Creates a new `IoVecMut` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. + #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut(sys::io::IoVecMut::new(buf)) + } +} + +#[unstable(feature = "iovec", issue = "58452")] +impl<'a> Deref for IoVecMut<'a> { + type Target = [u8]; + + #[inline] + fn deref(&self) -> &[u8] { + self.0.as_slice() + } +} + +#[unstable(feature = "iovec", issue = "58452")] +impl<'a> DerefMut for IoVecMut<'a> { + #[inline] + fn deref_mut(&mut self) -> &mut [u8] { + self.0.as_mut_slice() + } +} + +/// A buffer type used with `Write::write_vectored`. +/// +/// It is semantically a wrapper around an `&[u8]`, but is guaranteed to be +/// ABI compatible with the `iovec` type on Unix platforms and `WSABUF` on +/// Windows. +#[unstable(feature = "iovec", issue = "58452")] +#[repr(transparent)] +pub struct IoVec<'a>(sys::io::IoVec<'a>); + +#[unstable(feature = "iovec", issue = "58452")] +impl<'a> fmt::Debug for IoVec<'a> { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(self.0.as_slice(), fmt) + } +} + +impl<'a> IoVec<'a> { + /// Creates a new `IoVec` wrapping a byte slice. + /// + /// # Panics + /// + /// Panics on Windows if the slice is larger than 4GB. + #[unstable(feature = "iovec", issue = "58452")] + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec(sys::io::IoVec::new(buf)) + } +} + +#[unstable(feature = "iovec", issue = "58452")] +impl<'a> Deref for IoVec<'a> { + type Target = [u8]; + + #[inline] + fn deref(&self) -> &[u8] { + self.0.as_slice() + } +} + /// A type used to conditionally initialize buffers passed to `Read` methods. #[unstable(feature = "read_initializer", issue = "42788")] #[derive(Debug)] @@ -997,6 +1101,22 @@ pub trait Write { #[stable(feature = "rust1", since = "1.0.0")] fn write(&mut self, buf: &[u8]) -> Result; + /// Like `write`, except that it writes from a slice of buffers. + /// + /// Data is copied to from each buffer in order, with the final buffer + /// read from possibly being only partially consumed. This method must + /// behave as a call to `write` with the buffers concatenated would. + /// + /// The default implementation simply passes the first nonempty buffer to + /// `write`. + #[unstable(feature = "iovec", issue = "58452")] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), + None => Ok(0), + } + } + /// Flush this output stream, ensuring that all intermediately buffered /// contents reach their destination. /// @@ -1691,13 +1811,23 @@ impl Read for Chain { fn read(&mut self, buf: &mut [u8]) -> Result { if !self.done_first { match self.first.read(buf)? { - 0 if buf.len() != 0 => { self.done_first = true; } + 0 if buf.len() != 0 => self.done_first = true, n => return Ok(n), } } self.second.read(buf) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> Result { + if !self.done_first { + match self.first.read_vectored(bufs)? { + 0 if bufs.iter().any(|b| !b.is_empty()) => self.done_first = true, + n => return Ok(n), + } + } + self.second.read_vectored(bufs) + } + unsafe fn initializer(&self) -> Initializer { let initializer = self.first.initializer(); if initializer.should_initialize() { diff --git a/src/libstd/io/util.rs b/src/libstd/io/util.rs index 8df961a9add6b..5ce955eb1e4af 100644 --- a/src/libstd/io/util.rs +++ b/src/libstd/io/util.rs @@ -1,7 +1,7 @@ #![allow(missing_copy_implementations)] use fmt; -use io::{self, Read, Initializer, Write, ErrorKind, BufRead}; +use io::{self, Read, Initializer, Write, ErrorKind, BufRead, IoVec, IoVecMut}; use mem; /// Copies the entire contents of a reader into a writer. @@ -152,6 +152,15 @@ impl Read for Repeat { Ok(buf.len()) } + #[inline] + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let mut nwritten = 0; + for buf in bufs { + nwritten += self.read(buf)?; + } + Ok(nwritten) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -195,6 +204,13 @@ pub fn sink() -> Sink { Sink { _priv: () } } impl Write for Sink { #[inline] fn write(&mut self, buf: &[u8]) -> io::Result { Ok(buf.len()) } + + #[inline] + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + let total_len = bufs.iter().map(|b| b.len()).sum(); + Ok(total_len) + } + #[inline] fn flush(&mut self) -> io::Result<()> { Ok(()) } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6dd3a6cc0fdbd..ff72704bfbf69 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -187,7 +187,7 @@ //! [`sync`]: sync/index.html //! [`thread`]: thread/index.html //! [`use std::env`]: env/index.html -//! [`use`]: ../book/ch07-02-modules-and-use-to-control-scope-and-privacy.html#the-use-keyword-to-bring-paths-into-a-scope +//! [`use`]: ../book/ch07-02-defining-modules-to-control-scope-and-privacy.html //! [crates.io]: https://crates.io //! [deref-coercions]: ../book/ch15-02-deref.html#implicit-deref-coercions-with-functions-and-methods //! [files]: fs/struct.File.html @@ -234,6 +234,7 @@ #![feature(arbitrary_self_types)] #![feature(array_error_internals)] #![feature(asm)] +#![feature(bind_by_move_pattern_guards)] #![feature(box_syntax)] #![feature(c_variadic)] #![feature(cfg_target_has_atomic)] @@ -296,7 +297,6 @@ #![feature(str_internals)] #![feature(thread_local)] #![feature(toowned_clone_into)] -#![feature(try_from)] #![feature(try_reserve)] #![feature(unboxed_closures)] #![feature(untagged_unions)] diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index 51bd76ae4363e..3aa29f83b2938 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -1,7 +1,7 @@ use io::prelude::*; use fmt; -use io::{self, Initializer}; +use io::{self, Initializer, IoVec, IoVecMut}; use net::{ToSocketAddrs, SocketAddr, Shutdown}; use sys_common::net as net_imp; use sys_common::{AsInner, FromInner, IntoInner}; @@ -569,6 +569,10 @@ impl TcpStream { impl Read for TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + self.0.read_vectored(bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -577,12 +581,21 @@ impl Read for TcpStream { #[stable(feature = "rust1", since = "1.0.0")] impl Write for TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } + + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + self.0.write_vectored(bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } #[stable(feature = "rust1", since = "1.0.0")] impl Read for &TcpStream { fn read(&mut self, buf: &mut [u8]) -> io::Result { self.0.read(buf) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + self.0.read_vectored(bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -591,6 +604,11 @@ impl Read for &TcpStream { #[stable(feature = "rust1", since = "1.0.0")] impl Write for &TcpStream { fn write(&mut self, buf: &[u8]) -> io::Result { self.0.write(buf) } + + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + self.0.write_vectored(bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } } @@ -911,7 +929,7 @@ impl fmt::Debug for TcpListener { #[cfg(all(test, not(any(target_os = "cloudabi", target_os = "emscripten"))))] mod tests { - use io::ErrorKind; + use io::{ErrorKind, IoVec, IoVecMut}; use io::prelude::*; use net::*; use net::test::{next_test_ip4, next_test_ip6}; @@ -1184,6 +1202,53 @@ mod tests { }) } + #[test] + fn read_vectored() { + each_ip(&mut |addr| { + let srv = t!(TcpListener::bind(&addr)); + let mut s1 = t!(TcpStream::connect(&addr)); + let mut s2 = t!(srv.accept()).0; + + let len = s1.write(&[10, 11, 12]).unwrap(); + assert_eq!(len, 3); + + let mut a = []; + let mut b = [0]; + let mut c = [0; 3]; + let len = t!(s2.read_vectored( + &mut [IoVecMut::new(&mut a), IoVecMut::new(&mut b), IoVecMut::new(&mut c)], + )); + assert!(len > 0); + assert_eq!(b, [10]); + // some implementations don't support readv, so we may only fill the first buffer + assert!(len == 1 || c == [11, 12, 0]); + }) + } + + #[test] + fn write_vectored() { + each_ip(&mut |addr| { + let srv = t!(TcpListener::bind(&addr)); + let mut s1 = t!(TcpStream::connect(&addr)); + let mut s2 = t!(srv.accept()).0; + + let a = []; + let b = [10]; + let c = [11, 12]; + t!(s1.write_vectored(&[IoVec::new(&a), IoVec::new(&b), IoVec::new(&c)])); + + let mut buf = [0; 4]; + let len = t!(s2.read(&mut buf)); + // some implementations don't support writev, so we may only write the first buffer + if len == 1 { + assert_eq!(buf, [10, 0, 0, 0]); + } else { + assert_eq!(len, 3); + assert_eq!(buf, [10, 11, 12, 0]); + } + }) + } + #[test] fn double_bind() { each_ip(&mut |addr| { diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 240b92a17db4c..9f91a9f89eb76 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -78,7 +78,6 @@ use iter::{self, FusedIterator}; use ops::{self, Deref}; use rc::Rc; use str::FromStr; -use string::ParseError; use sync::Arc; use ffi::{OsStr, OsString}; @@ -1533,7 +1532,7 @@ impl From for PathBuf { #[stable(feature = "path_from_str", since = "1.32.0")] impl FromStr for PathBuf { - type Err = ParseError; + type Err = core::convert::Infallible; fn from_str(s: &str) -> Result { Ok(PathBuf::from(s)) diff --git a/src/libstd/sys/cloudabi/io.rs b/src/libstd/sys/cloudabi/io.rs new file mode 100644 index 0000000000000..8b02d3fd19d30 --- /dev/null +++ b/src/libstd/sys/cloudabi/io.rs @@ -0,0 +1,32 @@ +pub struct IoVec<'a>(&'a [u8]); + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } +} + +pub struct IoVecMut<'a>(&'a mut [u8]); + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + self.0 + } +} diff --git a/src/libstd/sys/cloudabi/mod.rs b/src/libstd/sys/cloudabi/mod.rs index cd621b769456a..d9bc21861c90d 100644 --- a/src/libstd/sys/cloudabi/mod.rs +++ b/src/libstd/sys/cloudabi/mod.rs @@ -1,4 +1,3 @@ -use io; use libc; use mem; @@ -10,6 +9,7 @@ pub mod backtrace; #[path = "../unix/cmath.rs"] pub mod cmath; pub mod condvar; +pub mod io; #[path = "../unix/memchr.rs"] pub mod memchr; pub mod mutex; @@ -32,24 +32,24 @@ pub use self::shims::*; #[allow(dead_code)] pub fn init() {} -pub fn decode_error_kind(errno: i32) -> io::ErrorKind { +pub fn decode_error_kind(errno: i32) -> ::io::ErrorKind { match errno { - x if x == abi::errno::ACCES as i32 => io::ErrorKind::PermissionDenied, - x if x == abi::errno::ADDRINUSE as i32 => io::ErrorKind::AddrInUse, - x if x == abi::errno::ADDRNOTAVAIL as i32 => io::ErrorKind::AddrNotAvailable, - x if x == abi::errno::AGAIN as i32 => io::ErrorKind::WouldBlock, - x if x == abi::errno::CONNABORTED as i32 => io::ErrorKind::ConnectionAborted, - x if x == abi::errno::CONNREFUSED as i32 => io::ErrorKind::ConnectionRefused, - x if x == abi::errno::CONNRESET as i32 => io::ErrorKind::ConnectionReset, - x if x == abi::errno::EXIST as i32 => io::ErrorKind::AlreadyExists, - x if x == abi::errno::INTR as i32 => io::ErrorKind::Interrupted, - x if x == abi::errno::INVAL as i32 => io::ErrorKind::InvalidInput, - x if x == abi::errno::NOENT as i32 => io::ErrorKind::NotFound, - x if x == abi::errno::NOTCONN as i32 => io::ErrorKind::NotConnected, - x if x == abi::errno::PERM as i32 => io::ErrorKind::PermissionDenied, - x if x == abi::errno::PIPE as i32 => io::ErrorKind::BrokenPipe, - x if x == abi::errno::TIMEDOUT as i32 => io::ErrorKind::TimedOut, - _ => io::ErrorKind::Other, + x if x == abi::errno::ACCES as i32 => ::io::ErrorKind::PermissionDenied, + x if x == abi::errno::ADDRINUSE as i32 => ::io::ErrorKind::AddrInUse, + x if x == abi::errno::ADDRNOTAVAIL as i32 => ::io::ErrorKind::AddrNotAvailable, + x if x == abi::errno::AGAIN as i32 => ::io::ErrorKind::WouldBlock, + x if x == abi::errno::CONNABORTED as i32 => ::io::ErrorKind::ConnectionAborted, + x if x == abi::errno::CONNREFUSED as i32 => ::io::ErrorKind::ConnectionRefused, + x if x == abi::errno::CONNRESET as i32 => ::io::ErrorKind::ConnectionReset, + x if x == abi::errno::EXIST as i32 => ::io::ErrorKind::AlreadyExists, + x if x == abi::errno::INTR as i32 => ::io::ErrorKind::Interrupted, + x if x == abi::errno::INVAL as i32 => ::io::ErrorKind::InvalidInput, + x if x == abi::errno::NOENT as i32 => ::io::ErrorKind::NotFound, + x if x == abi::errno::NOTCONN as i32 => ::io::ErrorKind::NotConnected, + x if x == abi::errno::PERM as i32 => ::io::ErrorKind::PermissionDenied, + x if x == abi::errno::PIPE as i32 => ::io::ErrorKind::BrokenPipe, + x if x == abi::errno::TIMEDOUT as i32 => ::io::ErrorKind::TimedOut, + _ => ::io::ErrorKind::Other, } } diff --git a/src/libstd/sys/cloudabi/shims/net.rs b/src/libstd/sys/cloudabi/shims/net.rs index b4caa899a75d9..869a0ef87a70e 100644 --- a/src/libstd/sys/cloudabi/shims/net.rs +++ b/src/libstd/sys/cloudabi/shims/net.rs @@ -1,5 +1,5 @@ use fmt; -use io; +use io::{self, IoVec, IoVecMut}; use net::{Ipv4Addr, Ipv6Addr, Shutdown, SocketAddr}; use time::Duration; use sys::{unsupported, Void}; @@ -42,10 +42,18 @@ impl TcpStream { match self.0 {} } + pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + match self.0 {} + } + pub fn write(&self, _: &[u8]) -> io::Result { match self.0 {} } + pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + match self.0 {} + } + pub fn peer_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/redox/io.rs b/src/libstd/sys/redox/io.rs new file mode 100644 index 0000000000000..8b02d3fd19d30 --- /dev/null +++ b/src/libstd/sys/redox/io.rs @@ -0,0 +1,32 @@ +pub struct IoVec<'a>(&'a [u8]); + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } +} + +pub struct IoVecMut<'a>(&'a mut [u8]); + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + self.0 + } +} diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index c106db8ddfaf5..c3878349bb329 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -1,6 +1,6 @@ #![allow(dead_code, missing_docs, nonstandard_style)] -use io::{self, ErrorKind}; +use ::io::{ErrorKind}; pub use libc::strlen; pub use self::rand::hashmap_random_keys; @@ -17,6 +17,7 @@ pub mod ext; pub mod fast_thread_local; pub mod fd; pub mod fs; +pub mod io; pub mod memchr; pub mod mutex; pub mod net; @@ -63,8 +64,8 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } } -pub fn cvt(result: Result) -> io::Result { - result.map_err(|err| io::Error::from_raw_os_error(err.errno)) +pub fn cvt(result: Result) -> ::io::Result { + result.map_err(|err| ::io::Error::from_raw_os_error(err.errno)) } #[doc(hidden)] @@ -82,9 +83,9 @@ macro_rules! impl_is_minus_one { impl_is_minus_one! { i8 i16 i32 i64 isize } -pub fn cvt_libc(t: T) -> io::Result { +pub fn cvt_libc(t: T) -> ::io::Result { if t.is_minus_one() { - Err(io::Error::last_os_error()) + Err(::io::Error::last_os_error()) } else { Ok(t) } diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index e0353b130bb48..abb9f72c324b6 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -1,5 +1,5 @@ use cmp; -use io::{self, Error, ErrorKind, Result}; +use io::{self, Error, ErrorKind, Result, IoVec, IoVecMut}; use mem; use net::{SocketAddr, Shutdown}; use path::Path; @@ -34,10 +34,24 @@ impl TcpStream { self.0.read(buf) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + match bufs.iter_mut().find(|b| !b.is_empty()) { + Some(buf) => self.read(buf), + None => Ok(0), + } + } + pub fn write(&self, buf: &[u8]) -> Result { self.0.write(buf) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + match bufs.iter().find(|b| !b.is_empty()) { + Some(buf) => self.write(buf), + None => Ok(0), + } + } + pub fn take_error(&self) -> Result> { Ok(None) } diff --git a/src/libstd/sys/sgx/io.rs b/src/libstd/sys/sgx/io.rs new file mode 100644 index 0000000000000..8b02d3fd19d30 --- /dev/null +++ b/src/libstd/sys/sgx/io.rs @@ -0,0 +1,32 @@ +pub struct IoVec<'a>(&'a [u8]); + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } +} + +pub struct IoVecMut<'a>(&'a mut [u8]); + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + self.0 + } +} diff --git a/src/libstd/sys/sgx/mod.rs b/src/libstd/sys/sgx/mod.rs index 4225ecbb20651..403dd61187fc3 100644 --- a/src/libstd/sys/sgx/mod.rs +++ b/src/libstd/sys/sgx/mod.rs @@ -3,7 +3,6 @@ //! This module contains the facade (aka platform-specific) implementations of //! OS level functionality for Fortanix SGX. -use io; use os::raw::c_char; use sync::atomic::{AtomicBool, Ordering}; @@ -20,6 +19,7 @@ pub mod env; pub mod ext; pub mod fd; pub mod fs; +pub mod io; pub mod memchr; pub mod mutex; pub mod net; @@ -41,12 +41,12 @@ pub fn init() { /// This function is used to implement functionality that simply doesn't exist. /// Programs relying on this functionality will need to deal with the error. -pub fn unsupported() -> io::Result { +pub fn unsupported() -> ::io::Result { Err(unsupported_err()) } -pub fn unsupported_err() -> io::Error { - io::Error::new(io::ErrorKind::Other, +pub fn unsupported_err() -> ::io::Error { + ::io::Error::new(::io::ErrorKind::Other, "operation not supported on SGX yet") } @@ -55,58 +55,58 @@ pub fn unsupported_err() -> io::Error { /// returned, the program might very well be able to function normally. This is /// what happens when `SGX_INEFFECTIVE_ERROR` is set to `true`. If it is /// `false`, the behavior is the same as `unsupported`. -pub fn sgx_ineffective(v: T) -> io::Result { +pub fn sgx_ineffective(v: T) -> ::io::Result { static SGX_INEFFECTIVE_ERROR: AtomicBool = AtomicBool::new(false); if SGX_INEFFECTIVE_ERROR.load(Ordering::Relaxed) { - Err(io::Error::new(io::ErrorKind::Other, + Err(::io::Error::new(::io::ErrorKind::Other, "operation can't be trusted to have any effect on SGX")) } else { Ok(v) } } -pub fn decode_error_kind(code: i32) -> io::ErrorKind { +pub fn decode_error_kind(code: i32) -> ::io::ErrorKind { use fortanix_sgx_abi::Error; // FIXME: not sure how to make sure all variants of Error are covered if code == Error::NotFound as _ { - io::ErrorKind::NotFound + ::io::ErrorKind::NotFound } else if code == Error::PermissionDenied as _ { - io::ErrorKind::PermissionDenied + ::io::ErrorKind::PermissionDenied } else if code == Error::ConnectionRefused as _ { - io::ErrorKind::ConnectionRefused + ::io::ErrorKind::ConnectionRefused } else if code == Error::ConnectionReset as _ { - io::ErrorKind::ConnectionReset + ::io::ErrorKind::ConnectionReset } else if code == Error::ConnectionAborted as _ { - io::ErrorKind::ConnectionAborted + ::io::ErrorKind::ConnectionAborted } else if code == Error::NotConnected as _ { - io::ErrorKind::NotConnected + ::io::ErrorKind::NotConnected } else if code == Error::AddrInUse as _ { - io::ErrorKind::AddrInUse + ::io::ErrorKind::AddrInUse } else if code == Error::AddrNotAvailable as _ { - io::ErrorKind::AddrNotAvailable + ::io::ErrorKind::AddrNotAvailable } else if code == Error::BrokenPipe as _ { - io::ErrorKind::BrokenPipe + ::io::ErrorKind::BrokenPipe } else if code == Error::AlreadyExists as _ { - io::ErrorKind::AlreadyExists + ::io::ErrorKind::AlreadyExists } else if code == Error::WouldBlock as _ { - io::ErrorKind::WouldBlock + ::io::ErrorKind::WouldBlock } else if code == Error::InvalidInput as _ { - io::ErrorKind::InvalidInput + ::io::ErrorKind::InvalidInput } else if code == Error::InvalidData as _ { - io::ErrorKind::InvalidData + ::io::ErrorKind::InvalidData } else if code == Error::TimedOut as _ { - io::ErrorKind::TimedOut + ::io::ErrorKind::TimedOut } else if code == Error::WriteZero as _ { - io::ErrorKind::WriteZero + ::io::ErrorKind::WriteZero } else if code == Error::Interrupted as _ { - io::ErrorKind::Interrupted + ::io::ErrorKind::Interrupted } else if code == Error::Other as _ { - io::ErrorKind::Other + ::io::ErrorKind::Other } else if code == Error::UnexpectedEof as _ { - io::ErrorKind::UnexpectedEof + ::io::ErrorKind::UnexpectedEof } else { - io::ErrorKind::Other + ::io::ErrorKind::Other } } diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index 6e86b06b28626..c4c2de43ff7df 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -1,5 +1,5 @@ use fmt; -use io; +use io::{self, IoVec, IoVecMut}; use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr, ToSocketAddrs}; use time::Duration; use sys::{unsupported, Void, sgx_ineffective, AsInner, FromInner, IntoInner, TryIntoInner}; @@ -103,10 +103,26 @@ impl TcpStream { self.inner.inner.read(buf) } + pub fn read_vectored(&self, buf: &mut [IoVecMut<'_>]) -> io::Result { + let buf = match buf.get_mut(0) { + Some(buf) => buf, + None => return Ok(0), + }; + self.read(buf) + } + pub fn write(&self, buf: &[u8]) -> io::Result { self.inner.inner.write(buf) } + pub fn write_vectored(&self, buf: &[IoVec<'_>]) -> io::Result { + let buf = match buf.get(0) { + Some(buf) => buf, + None => return Ok(0), + }; + self.write(buf) + } + pub fn peer_addr(&self) -> io::Result { addr_to_sockaddr(&self.peer_addr) } diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index acc064acfcd29..4b60ea654c1f1 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -18,7 +18,7 @@ mod libc { use ascii; use ffi::OsStr; use fmt; -use io::{self, Initializer}; +use io::{self, Initializer, IoVec, IoVecMut}; use mem; use net::{self, Shutdown}; use os::unix::ffi::OsStrExt; @@ -551,6 +551,10 @@ impl io::Read for UnixStream { io::Read::read(&mut &*self, buf) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + io::Read::read_vectored(&mut &*self, bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -563,6 +567,10 @@ impl<'a> io::Read for &'a UnixStream { self.0.read(buf) } + fn read_vectored(&mut self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + self.0.read_vectored(bufs) + } + #[inline] unsafe fn initializer(&self) -> Initializer { Initializer::nop() @@ -575,6 +583,10 @@ impl io::Write for UnixStream { io::Write::write(&mut &*self, buf) } + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + io::Write::write_vectored(&mut &*self, bufs) + } + fn flush(&mut self) -> io::Result<()> { io::Write::flush(&mut &*self) } @@ -586,6 +598,10 @@ impl<'a> io::Write for &'a UnixStream { self.0.write(buf) } + fn write_vectored(&mut self, bufs: &[IoVec<'_>]) -> io::Result { + self.0.write_vectored(bufs) + } + fn flush(&mut self) -> io::Result<()> { Ok(()) } @@ -1510,6 +1526,25 @@ mod test { thread.join().unwrap(); } + #[test] + fn vectored() { + let (mut s1, mut s2) = or_panic!(UnixStream::pair()); + + let len = or_panic!(s1.write_vectored( + &[IoVec::new(b"hello"), IoVec::new(b" "), IoVec::new(b"world!")], + )); + assert_eq!(len, 12); + + let mut buf1 = [0; 6]; + let mut buf2 = [0; 7]; + let len = or_panic!(s2.read_vectored( + &mut [IoVecMut::new(&mut buf1), IoVecMut::new(&mut buf2)], + )); + assert_eq!(len, 12); + assert_eq!(&buf1, b"hello "); + assert_eq!(&buf2, b"world!\0"); + } + #[test] fn pair() { let msg1 = b"hello"; diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 2cbd9536f4da7..6946b7b5dfa48 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -1,7 +1,7 @@ #![unstable(reason = "not public", issue = "0", feature = "fd")] use cmp; -use io::{self, Read, Initializer}; +use io::{self, Read, Initializer, IoVec, IoVecMut}; use libc::{self, c_int, c_void, ssize_t}; use mem; use sync::atomic::{AtomicBool, Ordering}; @@ -52,6 +52,15 @@ impl FileDesc { Ok(ret as usize) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + let ret = cvt(unsafe { + libc::readv(self.fd, + bufs.as_ptr() as *const libc::iovec, + cmp::min(bufs.len(), c_int::max_value() as usize) as c_int) + })?; + Ok(ret as usize) + } + pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { let mut me = self; (&mut me).read_to_end(buf) @@ -105,6 +114,15 @@ impl FileDesc { Ok(ret as usize) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + let ret = cvt(unsafe { + libc::writev(self.fd, + bufs.as_ptr() as *const libc::iovec, + cmp::min(bufs.len(), c_int::max_value() as usize) as c_int) + })?; + Ok(ret as usize) + } + pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; diff --git a/src/libstd/sys/unix/io.rs b/src/libstd/sys/unix/io.rs new file mode 100644 index 0000000000000..65e4c6e057750 --- /dev/null +++ b/src/libstd/sys/unix/io.rs @@ -0,0 +1,61 @@ +use marker::PhantomData; +use libc::{iovec, c_void}; +use slice; + +#[repr(transparent)] +pub struct IoVec<'a> { + vec: iovec, + _p: PhantomData<&'a [u8]>, +} + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec { + vec: iovec { + iov_base: buf.as_ptr() as *mut u8 as *mut c_void, + iov_len: buf.len() + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) + } + } +} + +pub struct IoVecMut<'a> { + vec: iovec, + _p: PhantomData<&'a mut [u8]>, +} + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut { + vec: iovec { + iov_base: buf.as_mut_ptr() as *mut c_void, + iov_len: buf.len() + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self.vec.iov_base as *mut u8, self.vec.iov_len) + } + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self.vec.iov_base as *mut u8, self.vec.iov_len) + } + } +} diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index 48037310c8d3a..4775e29fb5709 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -5,7 +5,7 @@ macro_rules! unimpl { pub mod net { #![allow(warnings)] use fmt; - use io; + use io::{self, IoVec, IoVecMut}; use libc; use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use sys_common::{AsInner, FromInner, IntoInner}; @@ -46,6 +46,10 @@ pub mod net { unimpl!(); } + pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + unimpl!(); + } + pub fn peek(&self, _: &mut [u8]) -> io::Result { unimpl!(); } @@ -62,6 +66,10 @@ pub mod net { unimpl!(); } + pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + unimpl!(); + } + pub fn set_timeout(&self, _: Option, _: libc::c_int) -> io::Result<()> { unimpl!(); } @@ -144,10 +152,18 @@ pub mod net { unimpl!(); } + pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + unimpl!(); + } + pub fn write(&self, _: &[u8]) -> io::Result { unimpl!(); } + pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + unimpl!(); + } + pub fn peer_addr(&self) -> io::Result { unimpl!(); } diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index b36c117fd09d4..0de1a223fbd12 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -1,6 +1,6 @@ #![allow(missing_docs, nonstandard_style)] -use io::{self, ErrorKind}; +use io::ErrorKind; use libc; #[cfg(any(rustdoc, target_os = "linux"))] pub use os::linux as platform; @@ -39,6 +39,7 @@ pub mod fast_thread_local; pub mod fd; pub mod fs; pub mod memchr; +pub mod io; pub mod mutex; #[cfg(not(target_os = "l4re"))] pub mod net; @@ -126,15 +127,15 @@ macro_rules! impl_is_minus_one { impl_is_minus_one! { i8 i16 i32 i64 isize } -pub fn cvt(t: T) -> io::Result { +pub fn cvt(t: T) -> ::io::Result { if t.is_minus_one() { - Err(io::Error::last_os_error()) + Err(::io::Error::last_os_error()) } else { Ok(t) } } -pub fn cvt_r(mut f: F) -> io::Result +pub fn cvt_r(mut f: F) -> ::io::Result where T: IsMinusOne, F: FnMut() -> T { diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index d780d71c37693..521d9b425179b 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -1,5 +1,5 @@ use ffi::CStr; -use io; +use io::{self, IoVec, IoVecMut}; use libc::{self, c_int, c_void, size_t, sockaddr, socklen_t, EAI_SYSTEM, MSG_PEEK}; use mem; use net::{SocketAddr, Shutdown}; @@ -241,6 +241,10 @@ impl Socket { self.recv_with_flags(buf, MSG_PEEK) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + self.0.read_vectored(bufs) + } + fn recv_from_with_flags(&self, buf: &mut [u8], flags: c_int) -> io::Result<(usize, SocketAddr)> { let mut storage: libc::sockaddr_storage = unsafe { mem::zeroed() }; @@ -269,6 +273,10 @@ impl Socket { self.0.write(buf) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + self.0.write_vectored(bufs) + } + pub fn set_timeout(&self, dur: Option, kind: libc::c_int) -> io::Result<()> { let timeout = match dur { Some(dur) => { diff --git a/src/libstd/sys/wasm/io.rs b/src/libstd/sys/wasm/io.rs new file mode 100644 index 0000000000000..8b02d3fd19d30 --- /dev/null +++ b/src/libstd/sys/wasm/io.rs @@ -0,0 +1,32 @@ +pub struct IoVec<'a>(&'a [u8]); + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + IoVec(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } +} + +pub struct IoVecMut<'a>(&'a mut [u8]); + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + IoVecMut(buf) + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + self.0 + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + self.0 + } +} diff --git a/src/libstd/sys/wasm/mod.rs b/src/libstd/sys/wasm/mod.rs index e21455ec6da75..e71c6bcd7fe76 100644 --- a/src/libstd/sys/wasm/mod.rs +++ b/src/libstd/sys/wasm/mod.rs @@ -14,7 +14,6 @@ //! compiling for wasm. That way it's a compile time error for something that's //! guaranteed to be a runtime error! -use io; use os::raw::c_char; use ptr; use sys::os_str::Buf; @@ -29,6 +28,7 @@ pub mod backtrace; pub mod cmath; pub mod env; pub mod fs; +pub mod io; pub mod memchr; pub mod net; pub mod os; @@ -63,17 +63,17 @@ cfg_if! { pub fn init() { } -pub fn unsupported() -> io::Result { +pub fn unsupported() -> ::io::Result { Err(unsupported_err()) } -pub fn unsupported_err() -> io::Error { - io::Error::new(io::ErrorKind::Other, +pub fn unsupported_err() -> ::io::Error { + ::io::Error::new(::io::ErrorKind::Other, "operation not supported on wasm yet") } -pub fn decode_error_kind(_code: i32) -> io::ErrorKind { - io::ErrorKind::Other +pub fn decode_error_kind(_code: i32) -> ::io::ErrorKind { + ::io::ErrorKind::Other } // This enum is used as the storage for a bunch of types which can't actually diff --git a/src/libstd/sys/wasm/net.rs b/src/libstd/sys/wasm/net.rs index 81e4e8255bf5a..d9f5d53843205 100644 --- a/src/libstd/sys/wasm/net.rs +++ b/src/libstd/sys/wasm/net.rs @@ -1,5 +1,5 @@ use fmt; -use io; +use io::{self, IoVec, IoVecMut}; use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; use time::Duration; use sys::{unsupported, Void}; @@ -40,10 +40,18 @@ impl TcpStream { match self.0 {} } + pub fn read_vectored(&self, _: &mut [IoVecMut<'_>]) -> io::Result { + match self.0 {} + } + pub fn write(&self, _: &[u8]) -> io::Result { match self.0 {} } + pub fn write_vectored(&self, _: &[IoVec<'_>]) -> io::Result { + match self.0 {} + } + pub fn peer_addr(&self) -> io::Result { match self.0 {} } diff --git a/src/libstd/sys/windows/c.rs b/src/libstd/sys/windows/c.rs index 28fd4df386e99..a78b599204b20 100644 --- a/src/libstd/sys/windows/c.rs +++ b/src/libstd/sys/windows/c.rs @@ -57,6 +57,9 @@ pub type LPWSAPROTOCOL_INFO = *mut WSAPROTOCOL_INFO; pub type LPSTR = *mut CHAR; pub type LPWSTR = *mut WCHAR; pub type LPFILETIME = *mut FILETIME; +pub type LPWSABUF = *mut WSABUF; +pub type LPWSAOVERLAPPED = *mut c_void; +pub type LPWSAOVERLAPPED_COMPLETION_ROUTINE = *mut c_void; pub type PCONDITION_VARIABLE = *mut CONDITION_VARIABLE; pub type PLARGE_INTEGER = *mut c_longlong; @@ -324,6 +327,12 @@ pub struct WSADATA { pub szSystemStatus: [u8; WSASYS_STATUS_LEN + 1], } +#[repr(C)] +pub struct WSABUF { + pub len: ULONG, + pub buf: *mut CHAR, +} + #[repr(C)] pub struct WSAPROTOCOL_INFO { pub dwServiceFlags1: DWORD, @@ -988,6 +997,22 @@ extern "system" { dwProcessId: DWORD, lpProtocolInfo: LPWSAPROTOCOL_INFO) -> c_int; + pub fn WSASend(s: SOCKET, + lpBuffers: LPWSABUF, + dwBufferCount: DWORD, + lpNumberOfBytesSent: LPDWORD, + dwFlags: DWORD, + lpOverlapped: LPWSAOVERLAPPED, + lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) + -> c_int; + pub fn WSARecv(s: SOCKET, + lpBuffers: LPWSABUF, + dwBufferCount: DWORD, + lpNumberOfBytesRecvd: LPDWORD, + lpFlags: LPDWORD, + lpOverlapped: LPWSAOVERLAPPED, + lpCompletionRoutine: LPWSAOVERLAPPED_COMPLETION_ROUTINE) + -> c_int; pub fn GetCurrentProcessId() -> DWORD; pub fn WSASocketW(af: c_int, kind: c_int, diff --git a/src/libstd/sys/windows/io.rs b/src/libstd/sys/windows/io.rs new file mode 100644 index 0000000000000..662e304792386 --- /dev/null +++ b/src/libstd/sys/windows/io.rs @@ -0,0 +1,63 @@ +use marker::PhantomData; +use slice; +use sys::c; + +#[repr(transparent)] +pub struct IoVec<'a> { + vec: c::WSABUF, + _p: PhantomData<&'a [u8]>, +} + +impl<'a> IoVec<'a> { + #[inline] + pub fn new(buf: &'a [u8]) -> IoVec<'a> { + assert!(buf.len() <= c::ULONG::max_value() as usize); + IoVec { + vec: c::WSABUF { + len: buf.len() as c::ULONG, + buf: buf.as_ptr() as *mut u8 as *mut c::CHAR, + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) + } + } +} + +pub struct IoVecMut<'a> { + vec: c::WSABUF, + _p: PhantomData<&'a mut [u8]>, +} + +impl<'a> IoVecMut<'a> { + #[inline] + pub fn new(buf: &'a mut [u8]) -> IoVecMut<'a> { + assert!(buf.len() <= c::ULONG::max_value() as usize); + IoVecMut { + vec: c::WSABUF { + len: buf.len() as c::ULONG, + buf: buf.as_mut_ptr() as *mut c::CHAR, + }, + _p: PhantomData, + } + } + + #[inline] + pub fn as_slice(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self.vec.buf as *mut u8, self.vec.len as usize) + } + } + + #[inline] + pub fn as_mut_slice(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self.vec.buf as *mut u8, self.vec.len as usize) + } + } +} diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index e97e436efbf71..56c76a169feb8 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -2,7 +2,7 @@ use ptr; use ffi::{OsStr, OsString}; -use io::{self, ErrorKind}; +use io::ErrorKind; use os::windows::ffi::{OsStrExt, OsStringExt}; use path::PathBuf; use time::Duration; @@ -26,6 +26,7 @@ pub mod ext; pub mod fast_thread_local; pub mod fs; pub mod handle; +pub mod io; pub mod memchr; pub mod mutex; pub mod net; @@ -75,12 +76,12 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } } -pub fn to_u16s>(s: S) -> io::Result> { - fn inner(s: &OsStr) -> io::Result> { +pub fn to_u16s>(s: S) -> ::io::Result> { + fn inner(s: &OsStr) -> ::io::Result> { let mut maybe_result: Vec = s.encode_wide().collect(); if maybe_result.iter().any(|&u| u == 0) { - return Err(io::Error::new(io::ErrorKind::InvalidInput, - "strings passed to WinAPI cannot contain NULs")); + return Err(::io::Error::new(::io::ErrorKind::InvalidInput, + "strings passed to WinAPI cannot contain NULs")); } maybe_result.push(0); Ok(maybe_result) @@ -102,7 +103,7 @@ pub fn to_u16s>(s: S) -> io::Result> { // Once the syscall has completed (errors bail out early) the second closure is // yielded the data which has been read from the syscall. The return value // from this closure is then the return value of the function. -fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result +fn fill_utf16_buf(mut f1: F1, f2: F2) -> ::io::Result where F1: FnMut(*mut u16, c::DWORD) -> c::DWORD, F2: FnOnce(&[u16]) -> T { @@ -134,7 +135,7 @@ fn fill_utf16_buf(mut f1: F1, f2: F2) -> io::Result c::SetLastError(0); let k = match f1(buf.as_mut_ptr(), n as c::DWORD) { 0 if c::GetLastError() == 0 => 0, - 0 => return Err(io::Error::last_os_error()), + 0 => return Err(::io::Error::last_os_error()), n => n, } as usize; if k == n && c::GetLastError() == c::ERROR_INSUFFICIENT_BUFFER { @@ -157,7 +158,7 @@ fn wide_char_to_multi_byte(code_page: u32, flags: u32, s: &[u16], no_default_char: bool) - -> io::Result> { + -> ::io::Result> { unsafe { let mut size = c::WideCharToMultiByte(code_page, flags, @@ -168,7 +169,7 @@ fn wide_char_to_multi_byte(code_page: u32, ptr::null(), ptr::null_mut()); if size == 0 { - return Err(io::Error::last_os_error()); + return Err(::io::Error::last_os_error()); } let mut buf = Vec::with_capacity(size as usize); @@ -185,10 +186,10 @@ fn wide_char_to_multi_byte(code_page: u32, if no_default_char { &mut used_default_char } else { ptr::null_mut() }); if size == 0 { - return Err(io::Error::last_os_error()); + return Err(::io::Error::last_os_error()); } if no_default_char && used_default_char == c::TRUE { - return Err(io::Error::new(io::ErrorKind::InvalidData, + return Err(::io::Error::new(::io::ErrorKind::InvalidData, "string cannot be converted to requested code page")); } @@ -220,9 +221,9 @@ macro_rules! impl_is_zero { impl_is_zero! { i8 i16 i32 i64 isize u8 u16 u32 u64 usize } -pub fn cvt(i: I) -> io::Result { +pub fn cvt(i: I) -> ::io::Result { if i.is_zero() { - Err(io::Error::last_os_error()) + Err(::io::Error::last_os_error()) } else { Ok(i) } diff --git a/src/libstd/sys/windows/net.rs b/src/libstd/sys/windows/net.rs index acda81dcde574..76be26a9d1a57 100644 --- a/src/libstd/sys/windows/net.rs +++ b/src/libstd/sys/windows/net.rs @@ -1,7 +1,7 @@ #![unstable(issue = "0", feature = "windows_net")] use cmp; -use io::{self, Read}; +use io::{self, Read, IoVec, IoVecMut}; use libc::{c_int, c_void, c_ulong, c_long}; use mem; use net::{SocketAddr, Shutdown}; @@ -207,6 +207,30 @@ impl Socket { self.recv_with_flags(buf, 0) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + // On unix when a socket is shut down all further reads return 0, so we + // do the same on windows to map a shut down socket to returning EOF. + let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let mut nread = 0; + let mut flags = 0; + unsafe { + let ret = c::WSARecv( + self.0, + bufs.as_mut_ptr() as *mut c::WSABUF, + len, + &mut nread, + &mut flags, + ptr::null_mut(), + ptr::null_mut(), + ); + match ret { + 0 => Ok(nread as usize), + _ if c::WSAGetLastError() == c::WSAESHUTDOWN => Ok(0), + _ => Err(last_error()), + } + } + } + pub fn peek(&self, buf: &mut [u8]) -> io::Result { self.recv_with_flags(buf, c::MSG_PEEK) } @@ -243,6 +267,23 @@ impl Socket { self.recv_from_with_flags(buf, c::MSG_PEEK) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + let len = cmp::min(bufs.len(), c::DWORD::max_value() as usize) as c::DWORD; + let mut nwritten = 0; + unsafe { + cvt(c::WSASend( + self.0, + bufs.as_ptr() as *const c::WSABUF as *mut c::WSABUF, + len, + &mut nwritten, + 0, + ptr::null_mut(), + ptr::null_mut(), + ))?; + } + Ok(nwritten as usize) + } + pub fn set_timeout(&self, dur: Option, kind: c_int) -> io::Result<()> { let timeout = match dur { diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index f75df3ea695c6..0d60593ce1f2f 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -1,7 +1,7 @@ use cmp; use ffi::CString; use fmt; -use io::{self, Error, ErrorKind}; +use io::{self, Error, ErrorKind, IoVec, IoVecMut}; use libc::{c_int, c_void}; use mem; use net::{SocketAddr, Shutdown, Ipv4Addr, Ipv6Addr}; @@ -255,6 +255,10 @@ impl TcpStream { self.inner.read(buf) } + pub fn read_vectored(&self, bufs: &mut [IoVecMut<'_>]) -> io::Result { + self.inner.read_vectored(bufs) + } + pub fn write(&self, buf: &[u8]) -> io::Result { let len = cmp::min(buf.len(), ::max_value() as usize) as wrlen_t; let ret = cvt(unsafe { @@ -266,6 +270,10 @@ impl TcpStream { Ok(ret as usize) } + pub fn write_vectored(&self, bufs: &[IoVec<'_>]) -> io::Result { + self.inner.write_vectored(bufs) + } + pub fn peer_addr(&self) -> io::Result { sockname(|buf, len| unsafe { c::getpeername(*self.inner.as_inner(), buf, len) diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 9c4945d74dbfe..b4bf6665d4e93 100644 --- a/src/libsyntax/ast.rs +++ b/src/libsyntax/ast.rs @@ -1643,6 +1643,8 @@ pub enum TyKind { Mac(Mac), /// Placeholder for a kind that has failed to be defined. Err, + /// Placeholder for a `va_list`. + CVarArgs, } impl TyKind { @@ -1802,7 +1804,7 @@ impl Arg { pub struct FnDecl { pub inputs: Vec, pub output: FunctionRetTy, - pub variadic: bool, + pub c_variadic: bool, } impl FnDecl { diff --git a/src/libsyntax/ext/build.rs b/src/libsyntax/ext/build.rs index 27b0cfb163077..0bdc7fd60cb1d 100644 --- a/src/libsyntax/ext/build.rs +++ b/src/libsyntax/ext/build.rs @@ -985,7 +985,7 @@ impl<'a> AstBuilder for ExtCtxt<'a> { P(ast::FnDecl { inputs, output, - variadic: false + c_variadic: false }) } diff --git a/src/libsyntax/feature_gate.rs b/src/libsyntax/feature_gate.rs index c9b441193b76d..fad370d768e8d 100644 --- a/src/libsyntax/feature_gate.rs +++ b/src/libsyntax/feature_gate.rs @@ -21,8 +21,9 @@ use crate::early_buffered_lints::BufferedEarlyLintId; use crate::source_map::Spanned; use crate::edition::{ALL_EDITIONS, Edition}; use crate::visit::{self, FnKind, Visitor}; -use crate::parse::ParseSess; +use crate::parse::{token, ParseSess}; use crate::symbol::Symbol; +use crate::tokenstream::TokenTree; use errors::{DiagnosticBuilder, Handler}; use rustc_data_structures::fx::FxHashMap; @@ -431,9 +432,6 @@ declare_features! ( // Added for testing E0705; perma-unstable. (active, test_2018_feature, "1.31.0", Some(0), Some(Edition::Edition2018)), - // support for arbitrary delimited token streams in non-macro attributes - (active, unrestricted_attribute_tokens, "1.30.0", Some(55208), None), - // Allows unsized rvalues at arguments and parameters. (active, unsized_locals, "1.30.0", Some(48055), None), @@ -473,6 +471,9 @@ declare_features! ( // #[repr(align(X))] on enums (active, repr_align_enum, "1.34.0", Some(57996), None), + + // Allows the use of C-variadics + (active, c_variadic, "1.34.0", Some(44930), None), ); declare_features! ( @@ -700,6 +701,8 @@ declare_features! ( (accepted, cfg_target_vendor, "1.33.0", Some(29718), None), // `extern crate self as foo;` puts local crate root into extern prelude under name `foo`. (accepted, extern_crate_self, "1.34.0", Some(56409), None), + // support for arbitrary delimited token streams in non-macro attributes + (accepted, unrestricted_attribute_tokens, "1.34.0", Some(55208), None), ); // If you change this, please modify `src/doc/unstable-book` as well. You must @@ -1660,13 +1663,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { match BUILTIN_ATTRIBUTES.iter().find(|(name, ..)| attr.path == name) { Some(&(name, _, template, _)) => self.check_builtin_attribute(attr, name, template), - None => if !self.context.features.unrestricted_attribute_tokens { - // Unfortunately, `parse_meta` cannot be called speculatively - // because it can report errors by itself, so we have to call it - // only if the feature is disabled. - if let Err(mut err) = attr.parse_meta(self.context.parse_sess) { - err.help("try enabling `#![feature(unrestricted_attribute_tokens)]`").emit() - } + None => if let Some(TokenTree::Token(_, token::Eq)) = attr.tokens.trees().next() { + // All key-value attributes are restricted to meta-item syntax. + attr.parse_meta(self.context.parse_sess).map_err(|mut err| err.emit()).ok(); } } } @@ -1905,6 +1904,11 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if header.asyncness.is_async() { gate_feature_post!(&self, async_await, span, "async fn is unstable"); } + + if fn_decl.c_variadic { + gate_feature_post!(&self, c_variadic, span, + "C-varaidic functions are unstable"); + } // Stability of const fn methods are covered in // `visit_trait_item` and `visit_impl_item` below; this is // because default methods don't pass through this point. @@ -1933,6 +1937,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { if block.is_none() { self.check_abi(sig.header.abi, ti.span); } + if sig.decl.c_variadic { + gate_feature_post!(&self, c_variadic, ti.span, + "C-varaidic functions are unstable"); + } if sig.header.constness.node == ast::Constness::Const { gate_feature_post!(&self, const_fn, ti.span, "const fn is unstable"); } diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs index 86849f580d081..032a0e993ae42 100644 --- a/src/libsyntax/mut_visit.rs +++ b/src/libsyntax/mut_visit.rs @@ -401,7 +401,8 @@ pub fn noop_visit_ty(ty: &mut P, vis: &mut T) { let Ty { id, node, span } = ty.deref_mut(); vis.visit_id(id); match node { - TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | TyKind::Never => {} + TyKind::Infer | TyKind::ImplicitSelf | TyKind::Err | + TyKind::Never | TyKind::CVarArgs => {} TyKind::Slice(ty) => vis.visit_ty(ty), TyKind::Ptr(mt) => vis.visit_mt(mt), TyKind::Rptr(lt, mt) => { @@ -672,7 +673,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, variadic: _ } = decl.deref_mut(); + let FnDecl { inputs, output, c_variadic: _ } = decl.deref_mut(); visit_vec(inputs, |input| vis.visit_arg(input)); match output { FunctionRetTy::Default(span) => vis.visit_span(span), diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 9020c8c6a2dc6..e7937f57002f3 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -158,11 +158,21 @@ impl<'a> Parser<'a> { self.parse_token_tree().into() } else if self.eat(&token::Eq) { let eq = TokenTree::Token(self.prev_span, token::Eq); - let tree = match self.token { - token::CloseDelim(_) | token::Eof => self.unexpected()?, - _ => self.parse_token_tree(), + let mut is_interpolated_expr = false; + if let token::Interpolated(nt) = &self.token { + if let token::NtExpr(..) = **nt { + is_interpolated_expr = true; + } + } + let tokens = if is_interpolated_expr { + // We need to accept arbitrary interpolated expressions to continue + // supporting things like `doc = $expr` that work on stable. + // Non-literal interpolated expressions are rejected after expansion. + self.parse_token_tree().into() + } else { + self.parse_unsuffixed_lit()?.tokens() }; - TokenStream::new(vec![eq.into(), tree.into()]) + TokenStream::from_streams(vec![eq.into(), tokens]) } else { TokenStream::empty() }; diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 7e900dfeb1eeb..5f3b08bf942c0 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -1457,12 +1457,12 @@ impl<'a> Parser<'a> { }; self.expect_keyword(keywords::Fn)?; - let (inputs, variadic) = self.parse_fn_args(false, true)?; + let (inputs, c_variadic) = self.parse_fn_args(false, true)?; let ret_ty = self.parse_ret_ty(false)?; let decl = P(FnDecl { inputs, output: ret_ty, - variadic, + c_variadic, }); Ok(TyKind::BareFn(P(BareFnTy { abi, @@ -1543,7 +1543,7 @@ impl<'a> Parser<'a> { // definition... // We don't allow argument names to be left off in edition 2018. - p.parse_arg_general(p.span.rust_2018(), true) + p.parse_arg_general(p.span.rust_2018(), true, false) })?; generics.where_clause = self.parse_where_clause()?; @@ -1613,7 +1613,7 @@ impl<'a> Parser<'a> { /// Parses an optional return type `[ -> TY ]` in a function declaration. fn parse_ret_ty(&mut self, allow_plus: bool) -> PResult<'a, FunctionRetTy> { if self.eat(&token::RArrow) { - Ok(FunctionRetTy::Ty(self.parse_ty_common(allow_plus, true)?)) + Ok(FunctionRetTy::Ty(self.parse_ty_common(allow_plus, true, false)?)) } else { Ok(FunctionRetTy::Default(self.span.shrink_to_lo())) } @@ -1621,7 +1621,7 @@ impl<'a> Parser<'a> { /// Parses a type. pub fn parse_ty(&mut self) -> PResult<'a, P> { - self.parse_ty_common(true, true) + self.parse_ty_common(true, true, false) } /// Parses a type in restricted contexts where `+` is not permitted. @@ -1631,11 +1631,11 @@ impl<'a> Parser<'a> { /// Example 2: `value1 as TYPE + value2` /// `+` is prohibited to avoid interactions with expression grammar. fn parse_ty_no_plus(&mut self) -> PResult<'a, P> { - self.parse_ty_common(false, true) + self.parse_ty_common(false, true, false) } - fn parse_ty_common(&mut self, allow_plus: bool, allow_qpath_recovery: bool) - -> PResult<'a, P> { + fn parse_ty_common(&mut self, allow_plus: bool, allow_qpath_recovery: bool, + allow_c_variadic: bool) -> PResult<'a, P> { maybe_whole!(self, NtTy, |x| x); let lo = self.span; @@ -1772,6 +1772,15 @@ impl<'a> Parser<'a> { TyKind::Path(None, path) } } + } else if self.check(&token::DotDotDot) { + if allow_c_variadic { + self.eat(&token::DotDotDot); + TyKind::CVarArgs + } else { + return Err(self.fatal( + "only foreign functions are allowed to be C-variadic" + )); + } } else { let msg = format!("expected type, found {}", self.this_token_descr()); return Err(self.fatal(&msg)); @@ -1959,7 +1968,8 @@ impl<'a> Parser<'a> { } /// This version of parse arg doesn't necessarily require identifier names. - fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool) -> PResult<'a, Arg> { + fn parse_arg_general(&mut self, require_name: bool, is_trait_item: bool, + allow_c_variadic: bool) -> PResult<'a, Arg> { maybe_whole!(self, NtArg, |x| x); if let Ok(Some(_)) = self.parse_self_arg() { @@ -2008,12 +2018,12 @@ impl<'a> Parser<'a> { } self.eat_incorrect_doc_comment("a method argument's type"); - (pat, self.parse_ty()?) + (pat, self.parse_ty_common(true, true, allow_c_variadic)?) } else { debug!("parse_arg_general ident_to_pat"); let parser_snapshot_before_ty = self.clone(); self.eat_incorrect_doc_comment("a method argument's type"); - let mut ty = self.parse_ty(); + let mut ty = self.parse_ty_common(true, true, allow_c_variadic); if ty.is_ok() && self.token != token::Comma && self.token != token::CloseDelim(token::Paren) { // This wasn't actually a type, but a pattern looking like a type, @@ -2032,6 +2042,11 @@ impl<'a> Parser<'a> { (pat, ty) } Err(mut err) => { + // If this is a C-variadic argument and we hit an error, return the + // error. + if self.token == token::DotDotDot { + return Err(err); + } // Recover from attempting to parse the argument as a type without pattern. err.cancel(); mem::replace(self, parser_snapshot_before_ty); @@ -2068,7 +2083,7 @@ impl<'a> Parser<'a> { /// Parses a single function argument. crate fn parse_arg(&mut self) -> PResult<'a, Arg> { - self.parse_arg_general(true, false) + self.parse_arg_general(true, false, false) } /// Parses an argument in a lambda header (e.g., `|arg, arg|`). @@ -2406,7 +2421,7 @@ impl<'a> Parser<'a> { } let span = lo.to(self.prev_span); let output = if self.eat(&token::RArrow) { - Some(self.parse_ty_common(false, false)?) + Some(self.parse_ty_common(false, false, false)?) } else { None }; @@ -6107,55 +6122,49 @@ impl<'a> Parser<'a> { Ok(where_clause) } - fn parse_fn_args(&mut self, named_args: bool, allow_variadic: bool) + fn parse_fn_args(&mut self, named_args: bool, allow_c_variadic: bool) -> PResult<'a, (Vec , bool)> { self.expect(&token::OpenDelim(token::Paren))?; let sp = self.span; - let mut variadic = false; + let mut c_variadic = false; let (args, recovered): (Vec>, bool) = self.parse_seq_to_before_end( &token::CloseDelim(token::Paren), SeqSep::trailing_allowed(token::Comma), |p| { - if p.token == token::DotDotDot { - p.bump(); - variadic = true; - if allow_variadic { - if p.token != token::CloseDelim(token::Paren) { - let span = p.span; - p.span_err(span, - "`...` must be last in argument list for variadic function"); - } - Ok(None) - } else { - let span = p.prev_span; - if p.token == token::CloseDelim(token::Paren) { - // continue parsing to present any further errors - p.struct_span_err( - span, - "only foreign functions are allowed to be variadic" - ).emit(); - Ok(Some(dummy_arg(span))) - } else { - // this function definition looks beyond recovery, stop parsing - p.span_err(span, - "only foreign functions are allowed to be variadic"); - Ok(None) - } - } + // If the argument is a C-variadic argument we should not + // enforce named arguments. + let enforce_named_args = if p.token == token::DotDotDot { + false } else { - match p.parse_arg_general(named_args, false) { - Ok(arg) => Ok(Some(arg)), - Err(mut e) => { - e.emit(); - let lo = p.prev_span; - // Skip every token until next possible arg or end. - p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(token::Paren)]); - // Create a placeholder argument for proper arg count (#34264). - let span = lo.to(p.prev_span); - Ok(Some(dummy_arg(span))) + named_args + }; + match p.parse_arg_general(enforce_named_args, false, + allow_c_variadic) { + Ok(arg) => { + if let TyKind::CVarArgs = arg.ty.node { + c_variadic = true; + if p.token != token::CloseDelim(token::Paren) { + let span = p.span; + p.span_err(span, + "`...` must be the last argument of a C-variadic function"); + Ok(None) + } else { + Ok(Some(arg)) + } + } else { + Ok(Some(arg)) } + }, + Err(mut e) => { + e.emit(); + let lo = p.prev_span; + // Skip every token until next possible arg or end. + p.eat_to_tokens(&[&token::Comma, &token::CloseDelim(token::Paren)]); + // Create a placeholder argument for proper arg count (issue #34264). + let span = lo.to(p.prev_span); + Ok(Some(dummy_arg(span))) } } } @@ -6167,24 +6176,24 @@ impl<'a> Parser<'a> { let args: Vec<_> = args.into_iter().filter_map(|x| x).collect(); - if variadic && args.is_empty() { + if c_variadic && args.is_empty() { self.span_err(sp, - "variadic function must be declared with at least one named argument"); + "C-variadic function must be declared with at least one named argument"); } - Ok((args, variadic)) + Ok((args, c_variadic)) } /// Parses the argument list and result type of a function declaration. - fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P> { + fn parse_fn_decl(&mut self, allow_c_variadic: bool) -> PResult<'a, P> { - let (args, variadic) = self.parse_fn_args(true, allow_variadic)?; + let (args, c_variadic) = self.parse_fn_args(true, allow_c_variadic)?; let ret_ty = self.parse_ret_ty(true)?; Ok(P(FnDecl { inputs: args, output: ret_ty, - variadic, + c_variadic, })) } @@ -6331,7 +6340,7 @@ impl<'a> Parser<'a> { Ok(P(FnDecl { inputs: fn_inputs, output: self.parse_ret_ty(true)?, - variadic: false + c_variadic: false })) } @@ -6357,7 +6366,7 @@ impl<'a> Parser<'a> { Ok(P(FnDecl { inputs: inputs_captures, output, - variadic: false + c_variadic: false })) } @@ -6389,7 +6398,8 @@ impl<'a> Parser<'a> { abi: Abi) -> PResult<'a, ItemInfo> { let (ident, mut generics) = self.parse_fn_header()?; - let decl = self.parse_fn_decl(false)?; + let allow_c_variadic = abi == Abi::C && unsafety == Unsafety::Unsafe; + let decl = self.parse_fn_decl(allow_c_variadic)?; generics.where_clause = self.parse_where_clause()?; let (inner_attrs, body) = self.parse_inner_attrs_and_block()?; let header = FnHeader { unsafety, asyncness, constness, abi }; diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs index dcf9815f6d1ba..4f4336c5b2714 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -1118,6 +1118,9 @@ impl<'a> State<'a> { ast::TyKind::Mac(ref m) => { self.print_mac(m)?; } + ast::TyKind::CVarArgs => { + self.s.word("...")?; + } } self.end() } @@ -2811,7 +2814,7 @@ impl<'a> State<'a> { -> io::Result<()> { self.popen()?; self.commasep(Inconsistent, &decl.inputs, |s, arg| s.print_arg(arg, false))?; - if decl.variadic { + if decl.c_variadic { self.s.word(", ...")?; } self.pclose()?; @@ -3238,7 +3241,7 @@ mod tests { let decl = ast::FnDecl { inputs: Vec::new(), output: ast::FunctionRetTy::Default(syntax_pos::DUMMY_SP), - variadic: false + c_variadic: false }; let generics = ast::Generics::default(); assert_eq!( diff --git a/src/libsyntax/tokenstream.rs b/src/libsyntax/tokenstream.rs index 283679e758b54..4ce308d015c00 100644 --- a/src/libsyntax/tokenstream.rs +++ b/src/libsyntax/tokenstream.rs @@ -254,7 +254,7 @@ impl TokenStream { } } - fn from_streams(mut streams: Vec) -> TokenStream { + pub(crate) fn from_streams(mut streams: Vec) -> TokenStream { match streams.len() { 0 => TokenStream::empty(), 1 => streams.pop().unwrap(), diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs index a002394c710fe..dd9f4f74d9e48 100644 --- a/src/libsyntax/visit.rs +++ b/src/libsyntax/visit.rs @@ -315,7 +315,7 @@ pub fn walk_ty<'a, V: Visitor<'a>>(visitor: &mut V, typ: &'a Ty) { walk_list!(visitor, visit_lifetime, opt_lifetime); visitor.visit_ty(&mutable_type.ty) } - TyKind::Never => {}, + TyKind::Never | TyKind::CVarArgs => {} TyKind::Tup(ref tuple_element_types) => { walk_list!(visitor, visit_ty, tuple_element_types); } diff --git a/src/stdsimd b/src/stdsimd index 9a60697044088..359845eb7cae8 160000 --- a/src/stdsimd +++ b/src/stdsimd @@ -1 +1 @@ -Subproject commit 9a60697044088f6704a40da78dee25eb6d55fd6f +Subproject commit 359845eb7cae85799dc2ec81f2fb05da0aa6276d diff --git a/src/test/codegen/c-variadic.rs b/src/test/codegen/c-variadic.rs new file mode 100644 index 0000000000000..09c18ed90b216 --- /dev/null +++ b/src/test/codegen/c-variadic.rs @@ -0,0 +1,69 @@ +// compile-flags: -C no-prepopulate-passes + +#![crate_type = "lib"] +#![feature(c_variadic)] +#![no_std] +use core::ffi::VaList; + +extern "C" { + fn foreign_c_variadic_0(_: i32, ...); + fn foreign_c_variadic_1(_: VaList, ...); +} + +pub unsafe extern "C" fn use_foreign_c_variadic_0() { + // Ensure that we correctly call foreign C-variadic functions. + // CHECK: invoke void (i32, ...) @foreign_c_variadic_0(i32 0) + foreign_c_variadic_0(0); + // CHECK: invoke void (i32, ...) @foreign_c_variadic_0(i32 0, i32 42) + foreign_c_variadic_0(0, 42i32); + // CHECK: invoke void (i32, ...) @foreign_c_variadic_0(i32 0, i32 42, i32 1024) + foreign_c_variadic_0(0, 42i32, 1024i32); + // CHECK: invoke void (i32, ...) @foreign_c_variadic_0(i32 0, i32 42, i32 1024, i32 0) + foreign_c_variadic_0(0, 42i32, 1024i32, 0i32); +} + +// Ensure that we do not remove the `va_list` passed to the foreign function when +// removing the "spoofed" `VaList` that is used by Rust defined C-variadics. +pub unsafe extern "C" fn use_foreign_c_variadic_1_0(ap: VaList) { + // CHECK: invoke void ({{.*}}*, ...) @foreign_c_variadic_1({{.*}} %ap) + foreign_c_variadic_1(ap); +} + +pub unsafe extern "C" fn use_foreign_c_variadic_1_1(ap: VaList) { + // CHECK: invoke void ({{.*}}*, ...) @foreign_c_variadic_1({{.*}} %ap, i32 42) + foreign_c_variadic_1(ap, 42i32); +} +pub unsafe extern "C" fn use_foreign_c_variadic_1_2(ap: VaList) { + // CHECK: invoke void ({{.*}}*, ...) @foreign_c_variadic_1({{.*}} %ap, i32 2, i32 42) + foreign_c_variadic_1(ap, 2i32, 42i32); +} + +pub unsafe extern "C" fn use_foreign_c_variadic_1_3(ap: VaList) { + // CHECK: invoke void ({{.*}}*, ...) @foreign_c_variadic_1({{.*}} %ap, i32 2, i32 42, i32 0) + foreign_c_variadic_1(ap, 2i32, 42i32, 0i32); +} + +// Ensure that `va_start` and `va_end` are properly injected. +#[no_mangle] +pub unsafe extern "C" fn c_variadic(n: i32, mut ap: ...) -> i32 { + // CHECK: call void @llvm.va_start + let mut sum = 0; + for _ in 0..n { + sum += ap.arg::(); + } + sum + // CHECK: call void @llvm.va_end +} + +// Ensure that we generate the correct `call` signature when calling a Rust +// defined C-variadic. +pub unsafe fn test_c_variadic_call() { + // CHECK: call i32 (i32, ...) @c_variadic(i32 0) + c_variadic(0); + // CHECK: call i32 (i32, ...) @c_variadic(i32 0, i32 42) + c_variadic(0, 42i32); + // CHECK: call i32 (i32, ...) @c_variadic(i32 0, i32 42, i32 1024) + c_variadic(0, 42i32, 1024i32); + // CHECK: call i32 (i32, ...) @c_variadic(i32 0, i32 42, i32 1024, i32 0) + c_variadic(0, 42i32, 1024i32, 0i32); +} diff --git a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs index d55aac1e40f4f..96a238afaec05 100644 --- a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs +++ b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/checkrust.rs @@ -18,8 +18,10 @@ macro_rules! continue_if { unsafe fn compare_c_str(ptr: *const c_char, val: &str) -> bool { let cstr0 = CStr::from_ptr(ptr); - let cstr1 = CString::new(val).unwrap(); - &*cstr1 == cstr0 + match CString::new(val) { + Ok(cstr1) => &*cstr1 == cstr0, + Err(_) => false, + } } #[no_mangle] @@ -68,3 +70,24 @@ pub unsafe extern "C" fn check_list_copy_0(mut ap: VaList) -> usize { } }) } + +#[no_mangle] +pub unsafe extern "C" fn check_varargs_0(_: c_int, mut ap: ...) -> usize { + continue_if!(ap.arg::() == 42); + continue_if!(compare_c_str(ap.arg::<*const c_char>(), "Hello, World!")); + 0 +} + +#[no_mangle] +pub unsafe extern "C" fn check_varargs_1(_: c_int, mut ap: ...) -> usize { + continue_if!(ap.arg::().floor() == 3.14f64.floor()); + continue_if!(ap.arg::() == 12); + continue_if!(ap.arg::() == 'A' as c_char); + continue_if!(ap.arg::() == 1); + 0 +} + +#[no_mangle] +pub unsafe extern "C" fn check_varargs_2(_: c_int, mut ap: ...) -> usize { + 0 +} diff --git a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/test.c b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/test.c index 95cf0ef46ca1e..91b060dce26f4 100644 --- a/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/test.c +++ b/src/test/run-make-fulldeps/c-link-to-rust-va-list-fn/test.c @@ -8,6 +8,9 @@ extern size_t check_list_0(va_list ap); extern size_t check_list_1(va_list ap); extern size_t check_list_2(va_list ap); extern size_t check_list_copy_0(va_list ap); +extern size_t check_varargs_0(int fixed, ...); +extern size_t check_varargs_1(int fixed, ...); +extern size_t check_varargs_2(int fixed, ...); int test_rust(size_t (*fn)(va_list), ...) { size_t ret = 0; @@ -26,5 +29,12 @@ int main(int argc, char* argv[]) { assert(test_rust(check_list_2, 3.14, 12l, 'a', 6.28, "Hello", 42, "World") == 0); assert(test_rust(check_list_copy_0, 6.28, 16, 'A', "Skip Me!", "Correct") == 0); + + assert(check_varargs_0(0, 42, "Hello, World!") == 0); + + assert(check_varargs_1(0, 3.14, 12l, 'A', 0x1LL) == 0); + + assert(check_varargs_2(0, "All", "of", "these", "are", "ignored", ".") == 0); + return 0; } diff --git a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs index 956bc5ad862ca..80e0b0102af75 100644 --- a/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs +++ b/src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs @@ -112,7 +112,7 @@ fn iter_exprs(depth: usize, f: &mut FnMut(P)) { let decl = P(FnDecl { inputs: vec![], output: FunctionRetTy::Default(DUMMY_SP), - variadic: false, + c_variadic: false, }); iter_exprs(depth - 1, &mut |e| g( ExprKind::Closure(CaptureBy::Value, diff --git a/src/test/run-pass/proc-macro/derive-b.rs b/src/test/run-pass/proc-macro/derive-b.rs index af48cabca99e4..da67534364b65 100644 --- a/src/test/run-pass/proc-macro/derive-b.rs +++ b/src/test/run-pass/proc-macro/derive-b.rs @@ -1,7 +1,5 @@ // aux-build:derive-b.rs -#![feature(unrestricted_attribute_tokens)] - extern crate derive_b; #[derive(Debug, PartialEq, derive_b::B, Eq, Copy, Clone)] diff --git a/src/test/run-pass/try-from-int-error-partial-eq.rs b/src/test/run-pass/try-from-int-error-partial-eq.rs index 83ede6759257d..e9b53f2d1c8df 100644 --- a/src/test/run-pass/try-from-int-error-partial-eq.rs +++ b/src/test/run-pass/try-from-int-error-partial-eq.rs @@ -1,4 +1,3 @@ -#![feature(try_from)] #![allow(unused_must_use)] use std::convert::TryFrom; diff --git a/src/test/run-pass/try_from.rs b/src/test/run-pass/try_from.rs index 4522ce3a8d617..e42f2c3e3930d 100644 --- a/src/test/run-pass/try_from.rs +++ b/src/test/run-pass/try_from.rs @@ -4,9 +4,9 @@ // This test was added to show the motivation for doing this // over `TryFrom` being blanket impl for all `T: From` -#![feature(try_from, never_type)] +#![feature(never_type)] -use std::convert::TryInto; +use std::convert::{TryInto, Infallible}; struct Foo { t: T, @@ -32,6 +32,6 @@ impl Into> for Foo { } pub fn main() { - let _: Result, !> = Foo { t: 10 }.try_into(); + let _: Result, Infallible> = Foo { t: 10 }.try_into(); } diff --git a/src/test/rustdoc/variadic.rs b/src/test/rustdoc/variadic.rs index bd8f1775b3d04..5af2aea21fcac 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/attr-eq-token-tree.rs b/src/test/ui/attr-eq-token-tree.rs index f28f76db9389d..6aacb9d572aea 100644 --- a/src/test/ui/attr-eq-token-tree.rs +++ b/src/test/ui/attr-eq-token-tree.rs @@ -1,6 +1,4 @@ -// compile-pass +#![feature(custom_attribute)] -#![feature(custom_attribute, unrestricted_attribute_tokens)] - -#[my_attr = !] // OK under feature gate +#[my_attr = !] //~ ERROR unexpected token: `!` fn main() {} diff --git a/src/test/ui/attr-eq-token-tree.stderr b/src/test/ui/attr-eq-token-tree.stderr new file mode 100644 index 0000000000000..57d6a4e0f16a2 --- /dev/null +++ b/src/test/ui/attr-eq-token-tree.stderr @@ -0,0 +1,8 @@ +error: unexpected token: `!` + --> $DIR/attr-eq-token-tree.rs:3:11 + | +LL | #[my_attr = !] //~ ERROR unexpected token: `!` + | ^ + +error: aborting due to previous error + diff --git a/src/test/ui/variadic/variadic-ffi.rs b/src/test/ui/c-variadic/variadic-ffi-1.rs similarity index 100% rename from src/test/ui/variadic/variadic-ffi.rs rename to src/test/ui/c-variadic/variadic-ffi-1.rs diff --git a/src/test/ui/variadic/variadic-ffi.stderr b/src/test/ui/c-variadic/variadic-ffi-1.stderr similarity index 51% rename from src/test/ui/variadic/variadic-ffi.stderr rename to src/test/ui/c-variadic/variadic-ffi-1.stderr index 617b1f46ea3fc..61d55ce0d3ef9 100644 --- a/src/test/ui/variadic/variadic-ffi.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-1.stderr @@ -1,8 +1,8 @@ -error[E0045]: variadic function must have C or cdecl calling convention - --> $DIR/variadic-ffi.rs:5:5 +error[E0045]: C-variadic function must have C or cdecl calling convention + --> $DIR/variadic-ffi-1.rs:5:5 | LL | fn printf(_: *const u8, ...); //~ ERROR: variadic function must have C or cdecl calling - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention error: aborting due to previous error diff --git a/src/test/ui/variadic/variadic-ffi-2.rs b/src/test/ui/c-variadic/variadic-ffi-2.rs similarity index 100% rename from src/test/ui/variadic/variadic-ffi-2.rs rename to src/test/ui/c-variadic/variadic-ffi-2.rs diff --git a/src/test/ui/variadic/variadic-ffi-2.stderr b/src/test/ui/c-variadic/variadic-ffi-2.stderr similarity index 53% rename from src/test/ui/variadic/variadic-ffi-2.stderr rename to src/test/ui/c-variadic/variadic-ffi-2.stderr index cb2a9f874b7b3..4c8b8d2b2e1a9 100644 --- a/src/test/ui/variadic/variadic-ffi-2.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-2.stderr @@ -1,8 +1,8 @@ -error[E0045]: variadic function must have C or cdecl calling convention +error[E0045]: C-variadic function must have C or cdecl calling convention --> $DIR/variadic-ffi-2.rs:3:11 | LL | fn baz(f: extern "stdcall" fn(usize, ...)) { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention error: aborting due to previous error diff --git a/src/test/ui/variadic/variadic-ffi-3.rs b/src/test/ui/c-variadic/variadic-ffi-3.rs similarity index 85% rename from src/test/ui/variadic/variadic-ffi-3.rs rename to src/test/ui/c-variadic/variadic-ffi-3.rs index 12b3426d9da18..c02d1f54e5649 100644 --- a/src/test/ui/variadic/variadic-ffi-3.rs +++ b/src/test/ui/c-variadic/variadic-ffi-3.rs @@ -14,12 +14,10 @@ fn main() { let x: unsafe extern "C" fn(f: isize, x: u8) = foo; //~^ ERROR: mismatched types //~| expected type `unsafe extern "C" fn(isize, u8)` - //~| found type `unsafe extern "C" fn(isize, u8, ...) {foo}` let y: extern "C" fn(f: isize, x: u8, ...) = bar; //~^ ERROR: mismatched types - //~| expected type `extern "C" fn(isize, u8, ...)` - //~| found type `extern "C" fn(isize, u8) {bar}` + //~| expected type `for<'r> extern "C" fn(isize, u8, std::ffi::VaList<'r>, ...)` foo(1, 2, 3f32); //~ ERROR can't pass `f32` to variadic function foo(1, 2, true); //~ ERROR can't pass `bool` to variadic function diff --git a/src/test/ui/variadic/variadic-ffi-3.stderr b/src/test/ui/c-variadic/variadic-ffi-3.stderr similarity index 90% rename from src/test/ui/variadic/variadic-ffi-3.stderr rename to src/test/ui/c-variadic/variadic-ffi-3.stderr index 0fecbbf36b803..82e3c6cd06fc5 100644 --- a/src/test/ui/variadic/variadic-ffi-3.stderr +++ b/src/test/ui/c-variadic/variadic-ffi-3.stderr @@ -23,49 +23,49 @@ 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 `unsafe extern "C" fn(isize, u8, ...) {foo}` + found type `for<'r> unsafe extern "C" fn(isize, u8, std::ffi::VaList<'r>, ...) {foo}` error[E0308]: mismatched types - --> $DIR/variadic-ffi-3.rs:19:54 + --> $DIR/variadic-ffi-3.rs:18:54 | LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar; | ^^^ expected variadic fn, found non-variadic function | - = note: expected type `extern "C" fn(isize, u8, ...)` + = note: expected type `for<'r> extern "C" fn(isize, u8, std::ffi::VaList<'r>, ...)` found type `extern "C" fn(isize, u8) {bar}` error[E0617]: can't pass `f32` to variadic function - --> $DIR/variadic-ffi-3.rs:24:19 + --> $DIR/variadic-ffi-3.rs:22:19 | LL | foo(1, 2, 3f32); //~ ERROR can't pass `f32` to variadic function | ^^^^ help: cast the value to `c_double`: `3f32 as c_double` error[E0617]: can't pass `bool` to variadic function - --> $DIR/variadic-ffi-3.rs:25:19 + --> $DIR/variadic-ffi-3.rs:23:19 | LL | foo(1, 2, true); //~ ERROR can't pass `bool` to variadic function | ^^^^ help: cast the value to `c_int`: `true as c_int` error[E0617]: can't pass `i8` to variadic function - --> $DIR/variadic-ffi-3.rs:26:19 + --> $DIR/variadic-ffi-3.rs:24:19 | LL | foo(1, 2, 1i8); //~ ERROR can't pass `i8` to variadic function | ^^^ help: cast the value to `c_int`: `1i8 as c_int` error[E0617]: can't pass `u8` to variadic function - --> $DIR/variadic-ffi-3.rs:27:19 + --> $DIR/variadic-ffi-3.rs:25:19 | LL | foo(1, 2, 1u8); //~ ERROR can't pass `u8` to variadic function | ^^^ help: cast the value to `c_uint`: `1u8 as c_uint` error[E0617]: can't pass `i16` to variadic function - --> $DIR/variadic-ffi-3.rs:28:19 + --> $DIR/variadic-ffi-3.rs:26:19 | LL | foo(1, 2, 1i16); //~ ERROR can't pass `i16` to variadic function | ^^^^ help: cast the value to `c_int`: `1i16 as c_int` error[E0617]: can't pass `u16` to variadic function - --> $DIR/variadic-ffi-3.rs:29:19 + --> $DIR/variadic-ffi-3.rs:27:19 | LL | foo(1, 2, 1u16); //~ ERROR can't pass `u16` to variadic function | ^^^^ help: cast the value to `c_uint`: `1u16 as c_uint` diff --git a/src/test/ui/c-variadic/variadic-ffi-4.rs b/src/test/ui/c-variadic/variadic-ffi-4.rs new file mode 100644 index 0000000000000..9101be5645646 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-4.rs @@ -0,0 +1,29 @@ +#![crate_type="lib"] +#![no_std] +#![feature(c_variadic)] + +use core::ffi::VaList; + +pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { + ap //~ ERROR: explicit lifetime required +} + +pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { + ap //~ ERROR: explicit lifetime required +} + +pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { + let _ = ap.copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime +} + +pub unsafe extern "C" fn no_escape3(_: usize, mut ap0: &mut VaList, mut ap1: ...) { + *ap0 = ap1; //~ ERROR: mismatched types +} + +pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { + ap0 = &mut ap1; + //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long + //~^^ ERROR: mismatched types + //~^^^ ERROR: mismatched types + //~^^^^ ERROR: cannot infer an appropriate lifetime +} diff --git a/src/test/ui/c-variadic/variadic-ffi-4.stderr b/src/test/ui/c-variadic/variadic-ffi-4.stderr new file mode 100644 index 0000000000000..1d752be065c4a --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-4.stderr @@ -0,0 +1,198 @@ +error[E0621]: explicit lifetime required in the type of `ap` + --> $DIR/variadic-ffi-4.rs:8:5 + | +LL | pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { + | --- help: add explicit lifetime `'a` to the type of `ap`: `core::ffi::VaList<'a>` +LL | ap //~ ERROR: explicit lifetime required + | ^^ lifetime `'a` required + +error[E0621]: explicit lifetime required in the type of `ap` + --> $DIR/variadic-ffi-4.rs:12:5 + | +LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { + | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaList<'static>` +LL | ap //~ ERROR: explicit lifetime required + | ^^ lifetime `'static` required + +error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements + --> $DIR/variadic-ffi-4.rs:16:28 + | +LL | let _ = ap.copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime + | ^^ + | +note: first, the lifetime cannot outlive the anonymous lifetime #2 defined on the body at 16:21... + --> $DIR/variadic-ffi-4.rs:16:21 + | +LL | let _ = ap.copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime + | ^^^^^^^^^^^ + = note: ...so that the expression is assignable: + expected core::ffi::VaList<'_> + found core::ffi::VaList<'_> +note: but, the lifetime must be valid for the method call at 16:13... + --> $DIR/variadic-ffi-4.rs:16:13 + | +LL | let _ = ap.copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime + | ^^^^^^^^^^^^^^^^^^^^ +note: ...so type `core::ffi::VaList<'_>` of expression is valid during the expression + --> $DIR/variadic-ffi-4.rs:16:13 + | +LL | let _ = ap.copy(|ap| { ap }); //~ ERROR: cannot infer an appropriate lifetime + | ^^^^^^^^^^^^^^^^^^^^ + +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:20:12 + | +LL | *ap0 = ap1; //~ ERROR: mismatched types + | ^^^ lifetime mismatch + | + = note: expected type `core::ffi::VaList<'_>` + found type `core::ffi::VaList<'_>` +note: 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 VaList, mut ap1: ...) { +LL | | *ap0 = ap1; //~ ERROR: mismatched types +LL | | } + | |_^ +note: ...does not necessarily outlive 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 VaList, mut ap1: ...) { +LL | | *ap0 = ap1; //~ ERROR: mismatched types +LL | | } + | |_^ + +error[E0490]: a value of type `core::ffi::VaList<'_>` is borrowed for too long + --> $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 23:1 + --> $DIR/variadic-ffi-4.rs:23:1 + | +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ +note: but the borrow lasts for the anonymous lifetime #3 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 VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:24:11 + | +LL | ap0 = &mut ap1; + | ^^^^^^^^ lifetime mismatch + | + = note: expected type `&mut core::ffi::VaList<'_>` + found type `&mut core::ffi::VaList<'_>` +note: the anonymous lifetime #3 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 VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ +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 VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ + +error[E0308]: mismatched types + --> $DIR/variadic-ffi-4.rs:24:11 + | +LL | ap0 = &mut ap1; + | ^^^^^^^^ lifetime mismatch + | + = note: expected type `&mut core::ffi::VaList<'_>` + found type `&mut core::ffi::VaList<'_>` +note: 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 VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ +note: ...does not necessarily outlive the anonymous lifetime #3 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 VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ + +error[E0495]: cannot infer an appropriate lifetime for borrow expression due to conflicting requirements + --> $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 23:1... + --> $DIR/variadic-ffi-4.rs:23:1 + | +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ +note: ...so that the type `core::ffi::VaList<'_>` is not borrowed for too long + --> $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 23:1... + --> $DIR/variadic-ffi-4.rs:23:1 + | +LL | / pub unsafe extern "C" fn no_escape4(_: usize, ap0: &mut VaList, mut ap1: ...) { +LL | | ap0 = &mut ap1; +LL | | //~^ ERROR: a value of type `core::ffi::VaList<'_>` is borrowed for too long +LL | | //~^^ ERROR: mismatched types +LL | | //~^^^ ERROR: mismatched types +LL | | //~^^^^ ERROR: cannot infer an appropriate lifetime +LL | | } + | |_^ +note: ...so that reference does not outlive borrowed content + --> $DIR/variadic-ffi-4.rs:24:11 + | +LL | ap0 = &mut ap1; + | ^^^^^^^^ + +error: aborting due to 8 previous errors + +Some errors occurred: E0308, E0490, E0495, E0621. +For more information about an error, try `rustc --explain E0308`. diff --git a/src/test/ui/c-variadic/variadic-ffi-5.rs b/src/test/ui/c-variadic/variadic-ffi-5.rs new file mode 100644 index 0000000000000..d96482ff4d17a --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-5.rs @@ -0,0 +1,31 @@ +#![crate_type="lib"] +#![no_std] +#![feature(c_variadic)] +// The tests in this file are similar to that of variadic-ffi-4, but this +// one enables nll. +#![feature(nll)] + +use core::ffi::VaList; + +pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { + ap //~ ERROR: explicit lifetime required +} + +pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { + ap //~ ERROR: explicit lifetime required +} + +pub unsafe extern "C" fn no_escape2(_: usize, ap: ...) { + let _ = ap.copy(|ap| { ap }); //~ ERROR: lifetime may not live long enough +} + +pub unsafe extern "C" fn no_escape3(_: usize, ap0: &mut VaList, mut ap1: ...) { + *ap0 = ap1; //~ ERROR: lifetime may not live long enough +} + +pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaList, mut ap1: ...) { + ap0 = &mut ap1; + //~^ ERROR: lifetime may not live long enough + //~^^ ERROR: lifetime may not live long enough + //~^^^ ERROR: `ap1` does not live long enough +} diff --git a/src/test/ui/c-variadic/variadic-ffi-5.stderr b/src/test/ui/c-variadic/variadic-ffi-5.stderr new file mode 100644 index 0000000000000..2d452872baf4e --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-5.stderr @@ -0,0 +1,73 @@ +error[E0621]: explicit lifetime required in the type of `ap` + --> $DIR/variadic-ffi-5.rs:11:5 + | +LL | pub unsafe extern "C" fn no_escape0<'a>(_: usize, ap: ...) -> VaList<'a> { + | --- help: add explicit lifetime `'a` to the type of `ap`: `core::ffi::VaList<'a>` +LL | ap //~ ERROR: explicit lifetime required + | ^^ lifetime `'a` required + +error[E0621]: explicit lifetime required in the type of `ap` + --> $DIR/variadic-ffi-5.rs:15:5 + | +LL | pub unsafe extern "C" fn no_escape1(_: usize, ap: ...) -> VaList<'static> { + | --- help: add explicit lifetime `'static` to the type of `ap`: `core::ffi::VaList<'static>` +LL | ap //~ ERROR: explicit lifetime required + | ^^ lifetime `'static` required + +error: lifetime may not live long enough + --> $DIR/variadic-ffi-5.rs:19:28 + | +LL | let _ = ap.copy(|ap| { ap }); //~ ERROR: lifetime may not live long enough + | --- ^^ returning this value requires that `'1` must outlive `'2` + | | | + | | return type of closure is core::ffi::VaList<'2> + | has type `core::ffi::VaList<'1>` + +error: lifetime may not live long enough + --> $DIR/variadic-ffi-5.rs:23:5 + | +LL | pub unsafe extern "C" fn no_escape3(_: usize, ap0: &mut VaList, mut ap1: ...) { + | --- ------- has type `core::ffi::VaList<'1>` + | | + | has type `&mut core::ffi::VaList<'2>` +LL | *ap0 = ap1; //~ ERROR: lifetime may not live long enough + | ^^^^^^^^^^ assignment requires that `'1` must outlive `'2` + +error: lifetime may not live long enough + --> $DIR/variadic-ffi-5.rs:27:5 + | +LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaList, mut ap1: ...) { + | ------- ------- has type `core::ffi::VaList<'2>` + | | + | has type `&mut core::ffi::VaList<'1>` +LL | ap0 = &mut ap1; + | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` + +error: lifetime may not live long enough + --> $DIR/variadic-ffi-5.rs:27:5 + | +LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaList, mut ap1: ...) { + | ------- ------- has type `core::ffi::VaList<'1>` + | | + | has type `&mut core::ffi::VaList<'2>` +LL | ap0 = &mut ap1; + | ^^^^^^^^^^^^^^ assignment requires that `'1` must outlive `'2` + +error[E0597]: `ap1` does not live long enough + --> $DIR/variadic-ffi-5.rs:27:11 + | +LL | pub unsafe extern "C" fn no_escape4(_: usize, mut ap0: &mut VaList, mut ap1: ...) { + | - let's call the lifetime of this reference `'1` +LL | ap0 = &mut ap1; + | ------^^^^^^^^ + | | | + | | borrowed value does not live long enough + | assignment requires that `ap1` is borrowed for `'1` +... +LL | } + | - `ap1` dropped here while still borrowed + +error: aborting due to 7 previous errors + +Some errors occurred: E0597, E0621. +For more information about an error, try `rustc --explain E0597`. diff --git a/src/test/ui/c-variadic/variadic-ffi-6.rs b/src/test/ui/c-variadic/variadic-ffi-6.rs new file mode 100644 index 0000000000000..4dd8a2d452181 --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-6.rs @@ -0,0 +1,13 @@ +#![crate_type="lib"] +#![feature(c_variadic)] + +pub unsafe extern "C" fn use_vararg_lifetime( + x: usize, + y: ... +) -> &usize { //~ ERROR missing lifetime specifier + &0 +} + +pub unsafe extern "C" fn use_normal_arg_lifetime(x: &usize, y: ...) -> &usize { // OK + x +} diff --git a/src/test/ui/c-variadic/variadic-ffi-6.stderr b/src/test/ui/c-variadic/variadic-ffi-6.stderr new file mode 100644 index 0000000000000..76bd18959a51f --- /dev/null +++ b/src/test/ui/c-variadic/variadic-ffi-6.stderr @@ -0,0 +1,11 @@ +error[E0106]: missing lifetime specifier + --> $DIR/variadic-ffi-6.rs:7:6 + | +LL | ) -> &usize { //~ ERROR missing lifetime specifier + | ^ help: consider giving it an explicit bounded or 'static lifetime: `&'static` + | + = help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0106`. diff --git a/src/test/ui/e0119/conflict-with-std.rs b/src/test/ui/e0119/conflict-with-std.rs index e639bc5db5e0f..6dc81f33dfcc4 100644 --- a/src/test/ui/e0119/conflict-with-std.rs +++ b/src/test/ui/e0119/conflict-with-std.rs @@ -1,4 +1,3 @@ -#![feature(try_from)] use std::marker::PhantomData; use std::convert::{TryFrom, AsRef}; diff --git a/src/test/ui/e0119/conflict-with-std.stderr b/src/test/ui/e0119/conflict-with-std.stderr index c2ae321aa5e50..1cfb3c1dabae4 100644 --- a/src/test/ui/e0119/conflict-with-std.stderr +++ b/src/test/ui/e0119/conflict-with-std.stderr @@ -1,5 +1,5 @@ error[E0119]: conflicting implementations of trait `std::convert::AsRef` for type `std::boxed::Box`: - --> $DIR/conflict-with-std.rs:7:1 + --> $DIR/conflict-with-std.rs:6:1 | LL | impl AsRef for Box { //~ ERROR conflicting implementations | ^^^^^^^^^^^^^^^^^^^^^^^^ @@ -9,7 +9,7 @@ LL | impl AsRef for Box { //~ ERROR conflicting implementations where T: ?Sized; error[E0119]: conflicting implementations of trait `std::convert::From` for type `S`: - --> $DIR/conflict-with-std.rs:14:1 + --> $DIR/conflict-with-std.rs:13:1 | LL | impl From for S { //~ ERROR conflicting implementations | ^^^^^^^^^^^^^^^^^^ @@ -18,7 +18,7 @@ LL | impl From for S { //~ ERROR conflicting implementations - impl std::convert::From for T; error[E0119]: conflicting implementations of trait `std::convert::TryFrom` for type `X`: - --> $DIR/conflict-with-std.rs:21:1 + --> $DIR/conflict-with-std.rs:20:1 | LL | impl TryFrom for X { //~ ERROR conflicting implementations | ^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/error-codes/E0045.stderr b/src/test/ui/error-codes/E0045.stderr index b38bbc169bd60..0ce91f0a40103 100644 --- a/src/test/ui/error-codes/E0045.stderr +++ b/src/test/ui/error-codes/E0045.stderr @@ -1,8 +1,8 @@ -error[E0045]: variadic function must have C or cdecl calling convention +error[E0045]: C-variadic function must have C or cdecl calling convention --> $DIR/E0045.rs:1:17 | LL | extern "Rust" { fn foo(x: u8, ...); } //~ ERROR E0045 - | ^^^^^^^^^^^^^^^^^^^ variadics require C or cdecl calling convention + | ^^^^^^^^^^^^^^^^^^^ C-variadics require C or cdecl calling convention error: aborting due to previous error diff --git a/src/test/ui/error-codes/E0617.rs b/src/test/ui/error-codes/E0617.rs index 9eed1225ab82d..51f13c7dbd540 100644 --- a/src/test/ui/error-codes/E0617.rs +++ b/src/test/ui/error-codes/E0617.rs @@ -22,7 +22,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 `unsafe extern "C" fn(*const i8, ...) {printf}` to variadic function - //~| HELP cast the value to `unsafe extern "C" fn(*const i8, ...)` + //~^ ERROR can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...) {printf}` to variadic function + //~| HELP cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)` } } diff --git a/src/test/ui/error-codes/E0617.stderr b/src/test/ui/error-codes/E0617.stderr index 486ca1fa92f15..8387d5c7e93a5 100644 --- a/src/test/ui/error-codes/E0617.stderr +++ b/src/test/ui/error-codes/E0617.stderr @@ -28,15 +28,15 @@ error[E0617]: can't pass `u16` to variadic function LL | printf(::std::ptr::null(), 0u16); | ^^^^ help: cast the value to `c_uint`: `0u16 as c_uint` -error[E0617]: can't pass `unsafe extern "C" fn(*const i8, ...) {printf}` to variadic function +error[E0617]: can't pass `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...) {printf}` to variadic function --> $DIR/E0617.rs:24:36 | LL | printf(::std::ptr::null(), printf); | ^^^^^^ -help: cast the value to `unsafe extern "C" fn(*const i8, ...)` +help: cast the value to `for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)` | -LL | printf(::std::ptr::null(), printf as unsafe extern "C" fn(*const i8, ...)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | printf(::std::ptr::null(), printf as for<'r> unsafe extern "C" fn(*const i8, std::ffi::VaList<'r>, ...)); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 6 previous errors diff --git a/src/test/ui/feature-gate/feature-gate-c_variadic.rs b/src/test/ui/feature-gate/feature-gate-c_variadic.rs new file mode 100644 index 0000000000000..5801a2a89e2c1 --- /dev/null +++ b/src/test/ui/feature-gate/feature-gate-c_variadic.rs @@ -0,0 +1,4 @@ +#![crate_type="lib"] + +pub unsafe extern "C" fn test(_: i32, ap: ...) { } +//~^ C-varaidic functions are unstable diff --git a/src/test/ui/feature-gate/feature-gate-c_variadic.stderr b/src/test/ui/feature-gate/feature-gate-c_variadic.stderr new file mode 100644 index 0000000000000..a876e16fdea41 --- /dev/null +++ b/src/test/ui/feature-gate/feature-gate-c_variadic.stderr @@ -0,0 +1,11 @@ +error[E0658]: C-varaidic functions are unstable (see issue #44930) + --> $DIR/feature-gate-c_variadic.rs:3:1 + | +LL | pub unsafe extern "C" fn test(_: i32, ap: ...) { } + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = help: add #![feature(c_variadic)] to the crate attributes to enable + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs b/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs deleted file mode 100644 index 181c8592c547b..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.rs +++ /dev/null @@ -1,7 +0,0 @@ -#![feature(custom_attribute)] - -#[my_attr(a b c d)] -//~^ ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `b` -//~| ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `c` -//~| ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `d` -fn main() {} diff --git a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr b/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr deleted file mode 100644 index 1ddf2ff6d640b..0000000000000 --- a/src/test/ui/feature-gates/feature-gate-unrestricted-attribute-tokens.stderr +++ /dev/null @@ -1,20 +0,0 @@ -error: expected one of `(`, `)`, `,`, `::`, or `=`, found `b` - --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:13 - | -LL | #[my_attr(a b c d)] - | ^ expected one of `(`, `)`, `,`, `::`, or `=` here - -error: expected one of `(`, `)`, `,`, `::`, or `=`, found `c` - --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:15 - | -LL | #[my_attr(a b c d)] - | ^ expected one of `(`, `)`, `,`, `::`, or `=` here - -error: expected one of `(`, `)`, `,`, `::`, or `=`, found `d` - --> $DIR/feature-gate-unrestricted-attribute-tokens.rs:3:17 - | -LL | #[my_attr(a b c d)] - | ^ expected one of `(`, `)`, `,`, `::`, or `=` here - -error: aborting due to 3 previous errors - diff --git a/src/test/ui/invalid/invalid-variadic-function.rs b/src/test/ui/invalid/invalid-variadic-function.rs index aea630e7c26a1..8d23f0e477077 100644 --- a/src/test/ui/invalid/invalid-variadic-function.rs +++ b/src/test/ui/invalid/invalid-variadic-function.rs @@ -1,3 +1,3 @@ extern "C" fn foo(x: u8, ...); -//~^ ERROR only foreign functions are allowed to be variadic +//~^ ERROR only foreign functions are allowed to be C-variadic //~| ERROR expected one of `->`, `where`, or `{`, found `;` diff --git a/src/test/ui/invalid/invalid-variadic-function.stderr b/src/test/ui/invalid/invalid-variadic-function.stderr index 7a0b8066fd52a..b2dbf8b919084 100644 --- a/src/test/ui/invalid/invalid-variadic-function.stderr +++ b/src/test/ui/invalid/invalid-variadic-function.stderr @@ -1,4 +1,4 @@ -error: only foreign functions are allowed to be variadic +error: only foreign functions are allowed to be C-variadic --> $DIR/invalid-variadic-function.rs:1:26 | LL | extern "C" fn foo(x: u8, ...); diff --git a/src/test/ui/macros/macro-attribute.rs b/src/test/ui/macros/macro-attribute.rs index 7ddac2745c5a4..f580dfa8e34ed 100644 --- a/src/test/ui/macros/macro-attribute.rs +++ b/src/test/ui/macros/macro-attribute.rs @@ -1,4 +1,2 @@ -#![feature(unrestricted_attribute_tokens)] - -#[doc = $not_there] //~ ERROR expected `]`, found `not_there` +#[doc = $not_there] //~ ERROR unexpected token: `$` fn main() { } diff --git a/src/test/ui/macros/macro-attribute.stderr b/src/test/ui/macros/macro-attribute.stderr index fd4e7252d530d..7314e48334893 100644 --- a/src/test/ui/macros/macro-attribute.stderr +++ b/src/test/ui/macros/macro-attribute.stderr @@ -1,8 +1,8 @@ -error: expected `]`, found `not_there` - --> $DIR/macro-attribute.rs:3:10 +error: unexpected token: `$` + --> $DIR/macro-attribute.rs:1:7 | -LL | #[doc = $not_there] //~ ERROR expected `]`, found `not_there` - | ^^^^^^^^^ expected `]` +LL | #[doc = $not_there] //~ ERROR unexpected token: `$` + | ^ error: aborting due to previous error diff --git a/src/test/ui/malformed/malformed-interpolated.rs b/src/test/ui/malformed/malformed-interpolated.rs new file mode 100644 index 0000000000000..e452435968bac --- /dev/null +++ b/src/test/ui/malformed/malformed-interpolated.rs @@ -0,0 +1,18 @@ +#![feature(custom_attribute)] + +macro_rules! check { + ($expr: expr) => ( + #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes + //~| ERROR unexpected token: `-0` + //~| ERROR unexpected token: `0 + 0` + use main as _; + ); +} + +check!("0"); // OK +check!(0); // OK +check!(0u8); // ERROR, see above +check!(-0); // ERROR, see above +check!(0 + 0); // ERROR, see above + +fn main() {} diff --git a/src/test/ui/malformed/malformed-interpolated.stderr b/src/test/ui/malformed/malformed-interpolated.stderr new file mode 100644 index 0000000000000..24aa590c4d903 --- /dev/null +++ b/src/test/ui/malformed/malformed-interpolated.stderr @@ -0,0 +1,31 @@ +error: suffixed literals are not allowed in attributes + --> $DIR/malformed-interpolated.rs:5:21 + | +LL | #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes + | ^^^^^ +... +LL | check!(0u8); // ERROR, see above + | ------------ in this macro invocation + | + = help: instead of using a suffixed literal (1u8, 1.0f32, etc.), use an unsuffixed version (1, 1.0, etc.). + +error: unexpected token: `-0` + --> $DIR/malformed-interpolated.rs:5:19 + | +LL | #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes + | ^ +... +LL | check!(-0); // ERROR, see above + | ----------- in this macro invocation + +error: unexpected token: `0 + 0` + --> $DIR/malformed-interpolated.rs:5:19 + | +LL | #[my_attr = $expr] //~ ERROR suffixed literals are not allowed in attributes + | ^ +... +LL | check!(0 + 0); // ERROR, see above + | -------------- in this macro invocation + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs b/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs index ea356d574f622..f8bcec78650e8 100644 --- a/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs +++ b/src/test/ui/marker_trait_attr/marker-attribute-with-values.rs @@ -1,5 +1,4 @@ #![feature(marker_trait_attr)] -#![feature(unrestricted_attribute_tokens)] #[marker(always)] trait Marker1 {} @@ -9,8 +8,8 @@ trait Marker1 {} trait Marker2 {} //~^^ ERROR attribute must be of the form -#[marker(key = value)] +#[marker(key = "value")] trait Marker3 {} -//~^^ ERROR expected unsuffixed literal or identifier, found value +//~^^ ERROR attribute must be of the form `#[marker]` fn main() {} diff --git a/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr b/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr index c683b393d84e9..2b31dcb4760a0 100644 --- a/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr +++ b/src/test/ui/marker_trait_attr/marker-attribute-with-values.stderr @@ -1,20 +1,20 @@ error: attribute must be of the form `#[marker]` - --> $DIR/marker-attribute-with-values.rs:4:1 + --> $DIR/marker-attribute-with-values.rs:3:1 | LL | #[marker(always)] | ^^^^^^^^^^^^^^^^^ error: attribute must be of the form `#[marker]` - --> $DIR/marker-attribute-with-values.rs:8:1 + --> $DIR/marker-attribute-with-values.rs:7:1 | LL | #[marker("never")] | ^^^^^^^^^^^^^^^^^^ -error: expected unsuffixed literal or identifier, found value - --> $DIR/marker-attribute-with-values.rs:12:10 +error: attribute must be of the form `#[marker]` + --> $DIR/marker-attribute-with-values.rs:11:1 | -LL | #[marker(key = value)] - | ^^^ +LL | #[marker(key = "value")] + | ^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to 3 previous errors diff --git a/src/test/ui/parser/attr-bad-meta-2.stderr b/src/test/ui/parser/attr-bad-meta-2.stderr index ddc7a4b034b7f..36e566b5aa41a 100644 --- a/src/test/ui/parser/attr-bad-meta-2.stderr +++ b/src/test/ui/parser/attr-bad-meta-2.stderr @@ -1,8 +1,8 @@ error: unexpected token: `]` - --> $DIR/attr-bad-meta-2.rs:1:9 + --> $DIR/attr-bad-meta-2.rs:1:8 | LL | #[path =] //~ ERROR unexpected token: `]` - | ^ unexpected token after this + | ^ error: aborting due to previous error diff --git a/src/test/ui/parser/attr-bad-meta.rs b/src/test/ui/parser/attr-bad-meta.rs index 7fe5427249141..8001977f5a39f 100644 --- a/src/test/ui/parser/attr-bad-meta.rs +++ b/src/test/ui/parser/attr-bad-meta.rs @@ -1,4 +1,2 @@ -#![feature(unrestricted_attribute_tokens)] - #[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*` mod m {} diff --git a/src/test/ui/parser/attr-bad-meta.stderr b/src/test/ui/parser/attr-bad-meta.stderr index 7351702ec9dce..693da95017d2e 100644 --- a/src/test/ui/parser/attr-bad-meta.stderr +++ b/src/test/ui/parser/attr-bad-meta.stderr @@ -1,5 +1,5 @@ error: expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*` - --> $DIR/attr-bad-meta.rs:3:7 + --> $DIR/attr-bad-meta.rs:1:7 | LL | #[path*] //~ ERROR expected one of `(`, `::`, `=`, `[`, `]`, or `{`, found `*` | ^ expected one of `(`, `::`, `=`, `[`, `]`, or `{` here diff --git a/src/test/ui/parser/recover-enum2.stderr b/src/test/ui/parser/recover-enum2.stderr index 2473420a77930..b308e644ad9f8 100644 --- a/src/test/ui/parser/recover-enum2.stderr +++ b/src/test/ui/parser/recover-enum2.stderr @@ -10,11 +10,11 @@ error: expected one of `!`, `(`, `)`, `+`, `,`, `::`, or `<`, found `{` LL | Nope(i32 {}) //~ ERROR: found `{` | ^ expected one of 7 possible tokens here -error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `::`, `<`, `?`, `[`, `_`, `crate`, `dyn`, `extern`, `fn`, `for`, `impl`, `pub`, `unsafe`, `}`, or lifetime, found `{` +error: expected one of `!`, `&&`, `&`, `(`, `)`, `*`, `+`, `,`, `...`, `::`, `<`, `?`, `[`, `_`, `crate`, `dyn`, `extern`, `fn`, `for`, `impl`, `pub`, `unsafe`, `}`, or lifetime, found `{` --> $DIR/recover-enum2.rs:27:22 | LL | Nope(i32 {}) //~ ERROR: found `{` - | ^ expected one of 23 possible tokens here + | ^ expected one of 24 possible tokens here error: expected expression, found reserved identifier `_` --> $DIR/recover-enum2.rs:32:22 diff --git a/src/test/ui/parser/variadic-ffi-3.rs b/src/test/ui/parser/variadic-ffi-3.rs index 13bce27bb8344..ce83cc87abe00 100644 --- a/src/test/ui/parser/variadic-ffi-3.rs +++ b/src/test/ui/parser/variadic-ffi-3.rs @@ -1,5 +1,5 @@ fn foo(x: isize, ...) { - //~^ ERROR: only foreign functions are allowed to be variadic + //~^ ERROR: only foreign functions are allowed to be C-variadic } fn main() {} diff --git a/src/test/ui/parser/variadic-ffi-3.stderr b/src/test/ui/parser/variadic-ffi-3.stderr index 150de9e63d39d..8ea4d194396fa 100644 --- a/src/test/ui/parser/variadic-ffi-3.stderr +++ b/src/test/ui/parser/variadic-ffi-3.stderr @@ -1,4 +1,4 @@ -error: only foreign functions are allowed to be variadic +error: only foreign functions are allowed to be C-variadic --> $DIR/variadic-ffi-3.rs:1:18 | LL | fn foo(x: isize, ...) { diff --git a/src/test/ui/parser/variadic-ffi-4.rs b/src/test/ui/parser/variadic-ffi-4.rs index 812ed256a5d32..5f8b3f8f539b8 100644 --- a/src/test/ui/parser/variadic-ffi-4.rs +++ b/src/test/ui/parser/variadic-ffi-4.rs @@ -1,5 +1,5 @@ extern "C" fn foo(x: isize, ...) { - //~^ ERROR: only foreign functions are allowed to be variadic + //~^ ERROR: only foreign functions are allowed to be C-variadic } fn main() {} diff --git a/src/test/ui/parser/variadic-ffi-4.stderr b/src/test/ui/parser/variadic-ffi-4.stderr index 2d036b0cf3792..69fbf84869c13 100644 --- a/src/test/ui/parser/variadic-ffi-4.stderr +++ b/src/test/ui/parser/variadic-ffi-4.stderr @@ -1,4 +1,4 @@ -error: only foreign functions are allowed to be variadic +error: only foreign functions are allowed to be C-variadic --> $DIR/variadic-ffi-4.rs:1:29 | LL | extern "C" fn foo(x: isize, ...) { diff --git a/src/test/ui/proc-macro/proc-macro-attributes.rs b/src/test/ui/proc-macro/proc-macro-attributes.rs index 1cc824e943c75..062053453ee42 100644 --- a/src/test/ui/proc-macro/proc-macro-attributes.rs +++ b/src/test/ui/proc-macro/proc-macro-attributes.rs @@ -8,7 +8,6 @@ extern crate derive_b; #[B(D)] //~ ERROR `B` is ambiguous #[B(E = "foo")] //~ ERROR `B` is ambiguous #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous - //~^ ERROR expected one of `(`, `)`, `,`, `::`, or `=`, found `tokens` #[derive(B)] struct B; diff --git a/src/test/ui/proc-macro/proc-macro-attributes.stderr b/src/test/ui/proc-macro/proc-macro-attributes.stderr index 7ac44c9354dd5..a5ec787ac67e6 100644 --- a/src/test/ui/proc-macro/proc-macro-attributes.stderr +++ b/src/test/ui/proc-macro/proc-macro-attributes.stderr @@ -13,7 +13,7 @@ LL | #[B] //~ ERROR `B` is ambiguous | ^ ambiguous name | note: `B` could refer to the derive helper attribute defined here - --> $DIR/proc-macro-attributes.rs:12:10 + --> $DIR/proc-macro-attributes.rs:11:10 | LL | #[derive(B)] | ^ @@ -30,7 +30,7 @@ LL | #[B(D)] //~ ERROR `B` is ambiguous | ^ ambiguous name | note: `B` could refer to the derive helper attribute defined here - --> $DIR/proc-macro-attributes.rs:12:10 + --> $DIR/proc-macro-attributes.rs:11:10 | LL | #[derive(B)] | ^ @@ -47,7 +47,7 @@ LL | #[B(E = "foo")] //~ ERROR `B` is ambiguous | ^ ambiguous name | note: `B` could refer to the derive helper attribute defined here - --> $DIR/proc-macro-attributes.rs:12:10 + --> $DIR/proc-macro-attributes.rs:11:10 | LL | #[derive(B)] | ^ @@ -64,7 +64,7 @@ LL | #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous | ^ ambiguous name | note: `B` could refer to the derive helper attribute defined here - --> $DIR/proc-macro-attributes.rs:12:10 + --> $DIR/proc-macro-attributes.rs:11:10 | LL | #[derive(B)] | ^ @@ -74,13 +74,7 @@ note: `B` could also refer to the derive macro imported here LL | #[macro_use] | ^^^^^^^^^^^^ -error: expected one of `(`, `)`, `,`, `::`, or `=`, found `tokens` - --> $DIR/proc-macro-attributes.rs:10:15 - | -LL | #[B(arbitrary tokens)] //~ ERROR `B` is ambiguous - | ^^^^^^ expected one of `(`, `)`, `,`, `::`, or `=` here - -error: aborting due to 6 previous errors +error: aborting due to 5 previous errors Some errors occurred: E0658, E0659. For more information about an error, try `rustc --explain E0658`. diff --git a/src/test/ui/proc-macro/proc-macro-gates.rs b/src/test/ui/proc-macro/proc-macro-gates.rs index b708f6303148a..af6bfa08aaa94 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.rs +++ b/src/test/ui/proc-macro/proc-macro-gates.rs @@ -19,7 +19,7 @@ mod _test2_inner { //~| ERROR: non-builtin inner attributes are unstable } -#[a = y] //~ ERROR: must only be followed by a delimiter token +#[a = "y"] //~ ERROR: must only be followed by a delimiter token fn _test3() {} fn attrs() { diff --git a/src/test/ui/proc-macro/proc-macro-gates.stderr b/src/test/ui/proc-macro/proc-macro-gates.stderr index c0bc06d358de9..abfcf09bfaf6c 100644 --- a/src/test/ui/proc-macro/proc-macro-gates.stderr +++ b/src/test/ui/proc-macro/proc-macro-gates.stderr @@ -33,8 +33,8 @@ LL | #![a] //~ ERROR: custom attributes cannot be applied to modules error: custom attribute invocations must be of the form #[foo] or #[foo(..)], the macro name must only be followed by a delimiter token --> $DIR/proc-macro-gates.rs:22:1 | -LL | #[a = y] //~ ERROR: must only be followed by a delimiter token - | ^^^^^^^^ +LL | #[a = "y"] //~ ERROR: must only be followed by a delimiter token + | ^^^^^^^^^^ error[E0658]: custom attributes cannot be applied to statements (see issue #54727) --> $DIR/proc-macro-gates.rs:31:5 diff --git a/src/test/ui/unrestricted-attribute-tokens.rs b/src/test/ui/unrestricted-attribute-tokens.rs index 9d8ba03eca567..4798f7b396cd6 100644 --- a/src/test/ui/unrestricted-attribute-tokens.rs +++ b/src/test/ui/unrestricted-attribute-tokens.rs @@ -1,6 +1,8 @@ // compile-pass -#![feature(custom_attribute, unrestricted_attribute_tokens)] +#![feature(custom_attribute)] #[my_attr(a b c d)] +#[my_attr[a b c d]] +#[my_attr{a b c d}] fn main() {} diff --git a/src/tools/clippy b/src/tools/clippy index 1fac380886097..7bc2e1d60d23a 160000 --- a/src/tools/clippy +++ b/src/tools/clippy @@ -1 +1 @@ -Subproject commit 1fac38088609747627b07807945224cf1ea642ca +Subproject commit 7bc2e1d60d23a2f6a31d7a04d40171372d80b5b3 diff --git a/src/tools/linkchecker/main.rs b/src/tools/linkchecker/main.rs index af704ce260dc4..9a6c97dbca015 100644 --- a/src/tools/linkchecker/main.rs +++ b/src/tools/linkchecker/main.rs @@ -134,7 +134,9 @@ fn check(cache: &mut Cache, file.ends_with("log/index.html") || file.ends_with("ty/struct.Slice.html") || file.ends_with("ty/enum.Attributes.html") || - file.ends_with("ty/struct.SymbolName.html") { + file.ends_with("ty/struct.SymbolName.html") || + file.ends_with("io/struct.IoVec.html") || + file.ends_with("io/struct.IoVecMut.html") { return None; } // FIXME(#32553) diff --git a/src/tools/tidy/src/unstable_book.rs b/src/tools/tidy/src/unstable_book.rs index 63196eda7cc5f..cd60f36b1d273 100644 --- a/src/tools/tidy/src/unstable_book.rs +++ b/src/tools/tidy/src/unstable_book.rs @@ -82,25 +82,27 @@ pub fn check(path: &path::Path, bad: &mut bool) { !lang_features.contains_key(name) }).collect(); + // Library features let unstable_lib_feature_names = collect_unstable_feature_names(&lib_features); let unstable_book_lib_features_section_file_names = collect_unstable_book_lib_features_section_file_names(path); - // Check for Unstable Book sections that don't have a corresponding unstable feature - for feature_name in &unstable_book_lib_features_section_file_names - - &unstable_lib_feature_names { - tidy_error!(bad, - "The Unstable Book has a 'library feature' section '{}' which doesn't \ - correspond to an unstable library feature", - feature_name) - } - // Language features - let unstable_lang_feature_names = collect_unstable_feature_names(&lang_features); let unstable_book_lang_features_section_file_names = collect_unstable_book_lang_features_section_file_names(path); + // Check for Unstable Book sections that don't have a corresponding unstable feature + for feature_name in &unstable_book_lib_features_section_file_names - + &unstable_lib_feature_names { + if !unstable_lang_feature_names.contains(&feature_name) { + tidy_error!(bad, + "The Unstable Book has a 'library feature' section '{}' which doesn't \ + correspond to an unstable library feature", + feature_name); + } + } + // Check for Unstable Book sections that don't have a corresponding unstable feature. for feature_name in &unstable_book_lang_features_section_file_names - &unstable_lang_feature_names {