diff --git a/.mailmap b/.mailmap index a2e3c581eabba..aae034dd938b5 100644 --- a/.mailmap +++ b/.mailmap @@ -54,9 +54,10 @@ Chris C Cerami Chris C Cerami Chris Thorn Chris Thorn Chris Vittal Christopher Vittal -Christian Poveda -Christian Poveda -Christian Poveda +Christian Poveda +Christian Poveda +Christian Poveda +Christian Poveda Clark Gaebel Clinton Ryan Corey Richardson Elaine "See More" Nemo diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8fbbd7c4a2e49..fc8ca5d07b212 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -367,7 +367,7 @@ labels to triage issues: to fix the issue. * The dark blue **final-comment-period** label marks bugs that are using the - RFC signoff functionality of [rfcbot][rfcbot] and are currently in the final + RFC signoff functionality of [rfcbot] and are currently in the final comment period. * Red, **I**-prefixed labels indicate the **importance** of the issue. The @@ -385,7 +385,7 @@ labels to triage issues: label. * The gray **proposed-final-comment-period** label marks bugs that are using - the RFC signoff functionality of [rfcbot][rfcbot] and are currently awaiting + the RFC signoff functionality of [rfcbot] and are currently awaiting signoff of all team members in order to enter the final comment period. * Pink, **regression**-prefixed labels track regressions from stable to the diff --git a/RELEASES.md b/RELEASES.md index 5afc6f9bdc0cb..e3597473f62fd 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -4951,10 +4951,10 @@ Stabilized APIs --------------- * [`std::panic`] -* [`std::panic::catch_unwind`][] (renamed from `recover`) -* [`std::panic::resume_unwind`][] (renamed from `propagate`) -* [`std::panic::AssertUnwindSafe`][] (renamed from `AssertRecoverSafe`) -* [`std::panic::UnwindSafe`][] (renamed from `RecoverSafe`) +* [`std::panic::catch_unwind`] (renamed from `recover`) +* [`std::panic::resume_unwind`] (renamed from `propagate`) +* [`std::panic::AssertUnwindSafe`] (renamed from `AssertRecoverSafe`) +* [`std::panic::UnwindSafe`] (renamed from `RecoverSafe`) * [`str::is_char_boundary`] * [`<*const T>::as_ref`] * [`<*mut T>::as_ref`] @@ -5234,18 +5234,18 @@ Libraries --------- * Stabilized APIs: - * [`str::encode_utf16`][] (renamed from `utf16_units`) - * [`str::EncodeUtf16`][] (renamed from `Utf16Units`) + * [`str::encode_utf16`] (renamed from `utf16_units`) + * [`str::EncodeUtf16`] (renamed from `Utf16Units`) * [`Ref::map`] * [`RefMut::map`] * [`ptr::drop_in_place`] * [`time::Instant`] * [`time::SystemTime`] * [`Instant::now`] - * [`Instant::duration_since`][] (renamed from `duration_from_earlier`) + * [`Instant::duration_since`] (renamed from `duration_from_earlier`) * [`Instant::elapsed`] * [`SystemTime::now`] - * [`SystemTime::duration_since`][] (renamed from `duration_from_earlier`) + * [`SystemTime::duration_since`] (renamed from `duration_from_earlier`) * [`SystemTime::elapsed`] * Various `Add`/`Sub` impls for `Time` and `SystemTime` * [`SystemTimeError`] @@ -5432,8 +5432,8 @@ Libraries * Stabilized APIs * `Path` - * [`Path::strip_prefix`][] (renamed from relative_from) - * [`path::StripPrefixError`][] (new error type returned from strip_prefix) + * [`Path::strip_prefix`] (renamed from relative_from) + * [`path::StripPrefixError`] (new error type returned from strip_prefix) * `Ipv4Addr` * [`Ipv4Addr::is_loopback`] * [`Ipv4Addr::is_private`] @@ -5646,7 +5646,7 @@ Libraries * Stabilized APIs: [`Read::read_exact`], - [`ErrorKind::UnexpectedEof`][] (renamed from `UnexpectedEOF`), + [`ErrorKind::UnexpectedEof`] (renamed from `UnexpectedEOF`), [`fs::DirBuilder`], [`fs::DirBuilder::new`], [`fs::DirBuilder::recursive`], [`fs::DirBuilder::create`], [`os::unix::fs::DirBuilderExt`], @@ -5659,11 +5659,11 @@ Libraries [`collections::hash_set::HashSet::drain`], [`collections::binary_heap::Drain`], [`collections::binary_heap::BinaryHeap::drain`], - [`Vec::extend_from_slice`][] (renamed from `push_all`), + [`Vec::extend_from_slice`] (renamed from `push_all`), [`Mutex::get_mut`], [`Mutex::into_inner`], [`RwLock::get_mut`], [`RwLock::into_inner`], - [`Iterator::min_by_key`][] (renamed from `min_by`), - [`Iterator::max_by_key`][] (renamed from `max_by`). + [`Iterator::min_by_key`] (renamed from `min_by`), + [`Iterator::max_by_key`] (renamed from `max_by`). * The [core library][1.6co] is stable, as are most of its APIs. * [The `assert_eq!` macro supports arguments that don't implement `Sized`][1.6ae], such as arrays. In this way it behaves more like diff --git a/src/doc/unstable-book/src/language-features/lang-items.md b/src/doc/unstable-book/src/language-features/lang-items.md index d4ad65e84b7b4..6f096e582f575 100644 --- a/src/doc/unstable-book/src/language-features/lang-items.md +++ b/src/doc/unstable-book/src/language-features/lang-items.md @@ -188,11 +188,7 @@ pub extern fn rust_begin_panic(info: &PanicInfo) -> ! { In many cases, you may need to manually link to the `compiler_builtins` crate when building a `no_std` binary. You may observe this via linker error messages -such as "```undefined reference to `__rust_probestack'```". Using this crate -also requires enabling the library feature `compiler_builtins_lib`. You can read -more about this [here][compiler-builtins-lib]. - -[compiler-builtins-lib]: ../library-features/compiler-builtins-lib.md +such as "```undefined reference to `__rust_probestack'```". ## More about the language items diff --git a/src/doc/unstable-book/src/library-features/compiler-builtins-lib.md b/src/doc/unstable-book/src/library-features/compiler-builtins-lib.md deleted file mode 100644 index 6c71c3f2ce191..0000000000000 --- a/src/doc/unstable-book/src/library-features/compiler-builtins-lib.md +++ /dev/null @@ -1,35 +0,0 @@ -# `compiler_builtins_lib` - -The tracking issue for this feature is: None. - ------------------------- - -This feature is required to link to the `compiler_builtins` crate which contains -"compiler intrinsics". Compiler intrinsics are software implementations of basic -operations like multiplication of `u64`s. These intrinsics are only required on -platforms where these operations don't directly map to a hardware instruction. - -You should never need to explicitly link to the `compiler_builtins` crate when -building "std" programs as `compiler_builtins` is already in the dependency -graph of `std`. But you may need it when building `no_std` **binary** crates. If -you get a *linker* error like: - -``` text -$PWD/src/main.rs:11: undefined reference to `__aeabi_lmul' -$PWD/src/main.rs:11: undefined reference to `__aeabi_uldivmod' -``` - -That means that you need to link to this crate. - -When you link to this crate, make sure it only appears once in your crate -dependency graph. Also, it doesn't matter where in the dependency graph you -place the `compiler_builtins` crate. - - - -``` rust,ignore -#![feature(compiler_builtins_lib)] -#![no_std] - -extern crate compiler_builtins; -``` diff --git a/src/etc/installer/msi/rust.wxs b/src/etc/installer/msi/rust.wxs index a2e378f7b1db4..a182bc4067a9f 100644 --- a/src/etc/installer/msi/rust.wxs +++ b/src/etc/installer/msi/rust.wxs @@ -85,7 +85,7 @@ - + diff --git a/src/liballoc/collections/binary_heap.rs b/src/liballoc/collections/binary_heap.rs index 0148711bb8625..c527b378f7465 100644 --- a/src/liballoc/collections/binary_heap.rs +++ b/src/liballoc/collections/binary_heap.rs @@ -1094,7 +1094,7 @@ impl FusedIterator for Iter<'_, T> {} /// An owning iterator over the elements of a `BinaryHeap`. /// -/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`][`BinaryHeap`] +/// This `struct` is created by the [`into_iter`] method on [`BinaryHeap`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`into_iter`]: struct.BinaryHeap.html#method.into_iter diff --git a/src/liballoc/collections/btree/map.rs b/src/liballoc/collections/btree/map.rs index 7d0a862d79e48..fa8aae04011ed 100644 --- a/src/liballoc/collections/btree/map.rs +++ b/src/liballoc/collections/btree/map.rs @@ -283,7 +283,7 @@ pub struct IterMut<'a, K: 'a, V: 'a> { /// An owning iterator over the entries of a `BTreeMap`. /// -/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`][`BTreeMap`] +/// This `struct` is created by the [`into_iter`] method on [`BTreeMap`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`into_iter`]: struct.BTreeMap.html#method.into_iter diff --git a/src/liballoc/collections/btree/set.rs b/src/liballoc/collections/btree/set.rs index 282d163141bc8..f5487426814a5 100644 --- a/src/liballoc/collections/btree/set.rs +++ b/src/liballoc/collections/btree/set.rs @@ -83,7 +83,7 @@ impl fmt::Debug for Iter<'_, T> { /// An owning iterator over the items of a `BTreeSet`. /// -/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`][`BTreeSet`] +/// This `struct` is created by the [`into_iter`] method on [`BTreeSet`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`BTreeSet`]: struct.BTreeSet.html diff --git a/src/liballoc/collections/linked_list.rs b/src/liballoc/collections/linked_list.rs index 4931093c55c99..29bf2fdb30cf7 100644 --- a/src/liballoc/collections/linked_list.rs +++ b/src/liballoc/collections/linked_list.rs @@ -105,7 +105,7 @@ impl fmt::Debug for IterMut<'_, T> { /// An owning iterator over the elements of a `LinkedList`. /// -/// This `struct` is created by the [`into_iter`] method on [`LinkedList`][`LinkedList`] +/// This `struct` is created by the [`into_iter`] method on [`LinkedList`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`into_iter`]: struct.LinkedList.html#method.into_iter diff --git a/src/liballoc/collections/vec_deque.rs b/src/liballoc/collections/vec_deque.rs index 9d2eec94a0c02..2cc450bb68a20 100644 --- a/src/liballoc/collections/vec_deque.rs +++ b/src/liballoc/collections/vec_deque.rs @@ -2474,7 +2474,7 @@ impl FusedIterator for IterMut<'_, T> {} /// An owning iterator over the elements of a `VecDeque`. /// -/// This `struct` is created by the [`into_iter`] method on [`VecDeque`][`VecDeque`] +/// This `struct` is created by the [`into_iter`] method on [`VecDeque`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`into_iter`]: struct.VecDeque.html#method.into_iter diff --git a/src/liballoc/fmt.rs b/src/liballoc/fmt.rs index 01d4913665c07..e6162e0f571e2 100644 --- a/src/liballoc/fmt.rs +++ b/src/liballoc/fmt.rs @@ -330,7 +330,7 @@ //! //! Additionally, the return value of this function is [`fmt::Result`] which is a //! type alias of [`Result`]`<(), `[`std::fmt::Error`]`>`. Formatting implementations -//! should ensure that they propagate errors from the [`Formatter`][`Formatter`] (e.g., when +//! should ensure that they propagate errors from the [`Formatter`] (e.g., when //! calling [`write!`]). However, they should never return errors spuriously. That //! is, a formatting implementation must and may only return an error if the //! passed-in [`Formatter`] returns an error. This is because, contrary to what diff --git a/src/liballoc/slice.rs b/src/liballoc/slice.rs index 2f6d10c027be3..7b83658fca60d 100644 --- a/src/liballoc/slice.rs +++ b/src/liballoc/slice.rs @@ -450,7 +450,8 @@ impl [T] { // and `rem` is the remaining part of `n`. // Using `Vec` to access `set_len()`. - let mut buf = Vec::with_capacity(self.len().checked_mul(n).expect("capacity overflow")); + let capacity = self.len().checked_mul(n).expect("capacity overflow"); + let mut buf = Vec::with_capacity(capacity); // `2^expn` repetition is done by doubling `buf` `expn`-times. buf.extend(self); @@ -476,7 +477,7 @@ impl [T] { // `rem` (`= n - 2^expn`) repetition is done by copying // first `rem` repetitions from `buf` itself. - let rem_len = self.len() * n - buf.len(); // `self.len() * rem` + let rem_len = capacity - buf.len(); // `self.len() * rem` if rem_len > 0 { // `buf.extend(buf[0 .. rem_len])`: unsafe { @@ -487,8 +488,7 @@ impl [T] { rem_len, ); // `buf.len() + rem_len` equals to `buf.capacity()` (`= self.len() * n`). - let buf_cap = buf.capacity(); - buf.set_len(buf_cap); + buf.set_len(capacity); } } buf diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index dcd7dc49526b6..93a51ccb20737 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -242,7 +242,7 @@ use crate::raw_vec::RawVec; /// ensures no unnecessary allocations or deallocations occur. Emptying a `Vec` /// and then filling it back up to the same [`len`] should incur no calls to /// the allocator. If you wish to free up unused memory, use -/// [`shrink_to_fit`][`shrink_to_fit`]. +/// [`shrink_to_fit`]. /// /// [`push`] and [`insert`] will never (re)allocate if the reported capacity is /// sufficient. [`push`] and [`insert`] *will* (re)allocate if @@ -2461,7 +2461,7 @@ where /// An iterator that moves out of a vector. /// -/// This `struct` is created by the `into_iter` method on [`Vec`][`Vec`] (provided +/// This `struct` is created by the `into_iter` method on [`Vec`] (provided /// by the [`IntoIterator`] trait). /// /// [`Vec`]: struct.Vec.html diff --git a/src/libcore/marker.rs b/src/libcore/marker.rs index 978d622156413..3b98bc1c272f0 100644 --- a/src/libcore/marker.rs +++ b/src/libcore/marker.rs @@ -142,7 +142,7 @@ pub trait Unsize { /// In either of the two scenarios above, we reject usage of such a constant in /// a pattern match. /// -/// See also the [structural match RFC][RFC1445], and [issue 63438][] which +/// See also the [structural match RFC][RFC1445], and [issue 63438] which /// motivated migrating from attribute-based design to this trait. /// /// [RFC1445]: https://github.com/rust-lang/rfcs/blob/master/text/1445-restrict-constants-in-patterns.md diff --git a/src/libcore/num/f32.rs b/src/libcore/num/f32.rs index fd7b7cf0b3490..f1f1bb13f0f24 100644 --- a/src/libcore/num/f32.rs +++ b/src/libcore/num/f32.rs @@ -226,7 +226,7 @@ impl f32 { } /// Returns `true` if the number is neither zero, infinite, - /// [subnormal][subnormal], or `NaN`. + /// [subnormal], or `NaN`. /// /// ``` /// use std::f32; diff --git a/src/libcore/num/f64.rs b/src/libcore/num/f64.rs index 540c6a529d7c8..5f9dc541b7d91 100644 --- a/src/libcore/num/f64.rs +++ b/src/libcore/num/f64.rs @@ -226,7 +226,7 @@ impl f64 { } /// Returns `true` if the number is neither zero, infinite, - /// [subnormal][subnormal], or `NaN`. + /// [subnormal], or `NaN`. /// /// ``` /// use std::f64; diff --git a/src/libcore/ops/function.rs b/src/libcore/ops/function.rs index 505a65cee3de0..04c7789fa4ff4 100644 --- a/src/libcore/ops/function.rs +++ b/src/libcore/ops/function.rs @@ -2,12 +2,12 @@ /// /// Instances of `Fn` can be called repeatedly without mutating state. /// -/// *This trait (`Fn`) is not to be confused with [function pointers][] +/// *This trait (`Fn`) is not to be confused with [function pointers] /// (`fn`).* /// /// `Fn` is implemented automatically by closures which only take immutable /// references to captured variables or don't capture anything at all, as well -/// as (safe) [function pointers][] (with some caveats, see their documentation +/// as (safe) [function pointers] (with some caveats, see their documentation /// for more details). Additionally, for any type `F` that implements `Fn`, `&F` /// implements `Fn`, too. /// @@ -78,7 +78,7 @@ pub trait Fn: FnMut { /// /// `FnMut` is implemented automatically by closures which take mutable /// references to captured variables, as well as all types that implement -/// [`Fn`], e.g., (safe) [function pointers][] (since `FnMut` is a supertrait of +/// [`Fn`], e.g., (safe) [function pointers] (since `FnMut` is a supertrait of /// [`Fn`]). Additionally, for any type `F` that implements `FnMut`, `&mut F` /// implements `FnMut`, too. /// @@ -162,7 +162,7 @@ pub trait FnMut: FnOnce { /// /// `FnOnce` is implemented automatically by closure that might consume captured /// variables, as well as all types that implement [`FnMut`], e.g., (safe) -/// [function pointers][] (since `FnOnce` is a supertrait of [`FnMut`]). +/// [function pointers] (since `FnOnce` is a supertrait of [`FnMut`]). /// /// Since both [`Fn`] and [`FnMut`] are subtraits of `FnOnce`, any instance of /// [`Fn`] or [`FnMut`] can be used where a `FnOnce` is expected. diff --git a/src/libcore/result.rs b/src/libcore/result.rs index ce4c8995a3c48..5628658c5bdf5 100644 --- a/src/libcore/result.rs +++ b/src/libcore/result.rs @@ -1370,7 +1370,7 @@ unsafe impl TrustedLen for IterMut<'_, A> {} /// The iterator yields one value if the result is [`Ok`], otherwise none. /// /// This struct is created by the [`into_iter`] method on -/// [`Result`][`Result`] (provided by the [`IntoIterator`] trait). +/// [`Result`] (provided by the [`IntoIterator`] trait). /// /// [`Ok`]: enum.Result.html#variant.Ok /// [`Result`]: enum.Result.html diff --git a/src/libpanic_unwind/seh.rs b/src/libpanic_unwind/seh.rs index 9a28c47ba9458..e1907ec4e5f32 100644 --- a/src/libpanic_unwind/seh.rs +++ b/src/libpanic_unwind/seh.rs @@ -41,7 +41,7 @@ //! are then recovered in the filter function to be written to the stack frame //! of the `try` intrinsic. //! -//! [win64]: http://msdn.microsoft.com/en-us/library/1eyas8tf.aspx +//! [win64]: https://docs.microsoft.com/en-us/cpp/build/exception-handling-x64 //! [llvm]: http://llvm.org/docs/ExceptionHandling.html#background-on-windows-exceptions #![allow(nonstandard_style)] diff --git a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs index 8f6fbd27a58af..69ebbe1fd3679 100644 --- a/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs +++ b/src/librustc/infer/error_reporting/nice_region_error/static_impl_trait.rs @@ -54,7 +54,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> { err.span_suggestion( fn_return_span, &format!( - "you can add a constraint to the return type to make it last \ + "you can add a bound to the return type to make it last \ less than `'static` and match {}", lifetime, ), diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 49b542af0a034..e8e1678561096 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -415,22 +415,30 @@ impl<'tcx, Tag> Scalar { } } + #[inline] + fn to_unsigned_with_bit_width(self, bits: u64) -> InterpResult<'static, u128> { + let sz = Size::from_bits(bits); + self.to_bits(sz) + } + + /// Converts the scalar to produce an `u8`. Fails if the scalar is a pointer. pub fn to_u8(self) -> InterpResult<'static, u8> { - let sz = Size::from_bits(8); - let b = self.to_bits(sz)?; - Ok(b as u8) + self.to_unsigned_with_bit_width(8).map(|v| v as u8) + } + + /// Converts the scalar to produce an `u16`. Fails if the scalar is a pointer. + pub fn to_u16(self) -> InterpResult<'static, u16> { + self.to_unsigned_with_bit_width(16).map(|v| v as u16) } + /// Converts the scalar to produce an `u32`. Fails if the scalar is a pointer. pub fn to_u32(self) -> InterpResult<'static, u32> { - let sz = Size::from_bits(32); - let b = self.to_bits(sz)?; - Ok(b as u32) + self.to_unsigned_with_bit_width(32).map(|v| v as u32) } + /// Converts the scalar to produce an `u64`. Fails if the scalar is a pointer. pub fn to_u64(self) -> InterpResult<'static, u64> { - let sz = Size::from_bits(64); - let b = self.to_bits(sz)?; - Ok(b as u64) + self.to_unsigned_with_bit_width(64).map(|v| v as u64) } pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> { @@ -438,25 +446,31 @@ impl<'tcx, Tag> Scalar { Ok(b as u64) } - pub fn to_i8(self) -> InterpResult<'static, i8> { - let sz = Size::from_bits(8); + #[inline] + fn to_signed_with_bit_width(self, bits: u64) -> InterpResult<'static, i128> { + let sz = Size::from_bits(bits); let b = self.to_bits(sz)?; - let b = sign_extend(b, sz) as i128; - Ok(b as i8) + Ok(sign_extend(b, sz) as i128) + } + + /// Converts the scalar to produce an `i8`. Fails if the scalar is a pointer. + pub fn to_i8(self) -> InterpResult<'static, i8> { + self.to_signed_with_bit_width(8).map(|v| v as i8) + } + + /// Converts the scalar to produce an `i16`. Fails if the scalar is a pointer. + pub fn to_i16(self) -> InterpResult<'static, i16> { + self.to_signed_with_bit_width(16).map(|v| v as i16) } + /// Converts the scalar to produce an `i32`. Fails if the scalar is a pointer. pub fn to_i32(self) -> InterpResult<'static, i32> { - let sz = Size::from_bits(32); - let b = self.to_bits(sz)?; - let b = sign_extend(b, sz) as i128; - Ok(b as i32) + self.to_signed_with_bit_width(32).map(|v| v as i32) } + /// Converts the scalar to produce an `i64`. Fails if the scalar is a pointer. pub fn to_i64(self) -> InterpResult<'static, i64> { - let sz = Size::from_bits(64); - let b = self.to_bits(sz)?; - let b = sign_extend(b, sz) as i128; - Ok(b as i64) + self.to_signed_with_bit_width(64).map(|v| v as i64) } pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> { diff --git a/src/librustc/ty/context.rs b/src/librustc/ty/context.rs index e99e00a366d37..2a8586b93370d 100644 --- a/src/librustc/ty/context.rs +++ b/src/librustc/ty/context.rs @@ -1610,13 +1610,11 @@ pub mod tls { use crate::dep_graph::TaskDeps; use crate::ty::query; - use errors::{Diagnostic, TRACK_DIAGNOSTICS}; + use errors::Diagnostic; use rustc_data_structures::sync::{self, Lock, Lrc}; use rustc_data_structures::thin_vec::ThinVec; use rustc_data_structures::OnDrop; - use std::fmt; use std::mem; - use syntax_pos; #[cfg(not(parallel_compiler))] use std::cell::Cell; @@ -1692,58 +1690,6 @@ pub mod tls { TLV.with(|tlv| tlv.get()) } - /// This is a callback from libsyntax as it cannot access the implicit state - /// in librustc otherwise. - fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { - with_opt(|tcx| { - if let Some(tcx) = tcx { - write!(f, "{}", tcx.sess.source_map().span_to_string(span)) - } else { - syntax_pos::default_span_debug(span, f) - } - }) - } - - /// This is a callback from libsyntax as it cannot access the implicit state - /// in librustc otherwise. It is used to when diagnostic messages are - /// emitted and stores them in the current query, if there is one. - fn track_diagnostic(diagnostic: &Diagnostic) { - with_context_opt(|icx| { - if let Some(icx) = icx { - if let Some(ref diagnostics) = icx.diagnostics { - let mut diagnostics = diagnostics.lock(); - diagnostics.extend(Some(diagnostic.clone())); - } - } - }) - } - - /// Sets up the callbacks from libsyntax on the current thread. - pub fn with_thread_locals(f: F) -> R - where - F: FnOnce() -> R, - { - syntax_pos::SPAN_DEBUG.with(|span_dbg| { - let original_span_debug = span_dbg.get(); - span_dbg.set(span_debug); - - let _on_drop = OnDrop(move || { - span_dbg.set(original_span_debug); - }); - - TRACK_DIAGNOSTICS.with(|current| { - let original = current.get(); - current.set(track_diagnostic); - - let _on_drop = OnDrop(move || { - current.set(original); - }); - - f() - }) - }) - } - /// Sets `context` as the new current `ImplicitCtxt` for the duration of the function `f`. #[inline] pub fn enter_context<'a, 'tcx, F, R>(context: &ImplicitCtxt<'a, 'tcx>, f: F) -> R diff --git a/src/librustc/ty/query/job.rs b/src/librustc/ty/query/job.rs index 7361485c55d9f..fbcbfae9f8f4f 100644 --- a/src/librustc/ty/query/job.rs +++ b/src/librustc/ty/query/job.rs @@ -435,13 +435,14 @@ pub unsafe fn handle_deadlock() { let syntax_pos_globals = syntax_pos::GLOBALS.with(|syntax_pos_globals| syntax_pos_globals as *const _); let syntax_pos_globals = &*syntax_pos_globals; + let syntax_globals = syntax::GLOBALS.with(|syntax_globals| syntax_globals as *const _); + let syntax_globals = &*syntax_globals; thread::spawn(move || { tls::GCX_PTR.set(gcx_ptr, || { - syntax_pos::GLOBALS.set(syntax_pos_globals, || { - syntax_pos::GLOBALS.set(syntax_pos_globals, || { - tls::with_thread_locals(|| tls::with_global(|tcx| deadlock(tcx, ®istry))) - }) - }) + syntax::GLOBALS.set(syntax_globals, || { + syntax_pos::GLOBALS + .set(syntax_pos_globals, || tls::with_global(|tcx| deadlock(tcx, ®istry))) + }); }) }); } diff --git a/src/librustc_codegen_llvm/metadata.rs b/src/librustc_codegen_llvm/metadata.rs index d328144a15e12..abe34bb148ce5 100644 --- a/src/librustc_codegen_llvm/metadata.rs +++ b/src/librustc_codegen_llvm/metadata.rs @@ -97,7 +97,7 @@ pub fn metadata_section_name(target: &Target) -> &'static str { // > Executable images do not use a string table and do not support // > section names longer than 8 characters // - // https://msdn.microsoft.com/en-us/library/windows/hardware/gg463119.aspx + // https://docs.microsoft.com/en-us/windows/win32/debug/pe-format // // As a result, we choose a slightly shorter name! As to why // `.note.rustc` works on MinGW, that's another good question... diff --git a/src/librustc_codegen_ssa/back/command.rs b/src/librustc_codegen_ssa/back/command.rs index 5595386be2431..dcc16416e5e87 100644 --- a/src/librustc_codegen_ssa/back/command.rs +++ b/src/librustc_codegen_ssa/back/command.rs @@ -168,8 +168,8 @@ impl Command { // error code if we fail to spawn and automatically re-spawning the // linker with smaller arguments. // - // [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx - // [2]: https://blogs.msdn.microsoft.com/oldnewthing/20031210-00/?p=41553 + // [1]: https://docs.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-createprocessa + // [2]: https://devblogs.microsoft.com/oldnewthing/?p=41553 let estimated_command_line_len = self.args.iter().map(|a| a.len()).sum::(); estimated_command_line_len > 1024 * 6 diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index f3420f9a9f9fd..c7a599a5749b7 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1044,7 +1044,7 @@ pub fn exec_linker( fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if self.is_like_msvc { // This is "documented" at - // https://msdn.microsoft.com/en-us/library/4xdcbak7.aspx + // https://docs.microsoft.com/en-us/cpp/build/reference/at-specify-a-linker-response-file // // Unfortunately there's not a great specification of the // syntax I could find online (at least) but some local diff --git a/src/librustc_codegen_ssa/mir/block.rs b/src/librustc_codegen_ssa/mir/block.rs index e856be0eeb3fc..a89b170c649f6 100644 --- a/src/librustc_codegen_ssa/mir/block.rs +++ b/src/librustc_codegen_ssa/mir/block.rs @@ -618,14 +618,17 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { if let mir::PlaceRef { base: &PlaceBase::Static(box Static { - kind: StaticKind::Promoted(promoted, _), + kind: StaticKind::Promoted(promoted, substs), ty, - def_id: _, + def_id, }), projection: &[], } = place.as_ref() { - let c = bx.tcx().const_eval_promoted(self.instance, promoted); + let c = bx.tcx().const_eval_promoted( + Instance::new(def_id, self.monomorphize(&substs)), + promoted, + ); let (llval, ty) = self.simd_shuffle_indices( &bx, terminator.source_info.span, diff --git a/src/librustc_data_structures/atomic_ref.rs b/src/librustc_data_structures/atomic_ref.rs new file mode 100644 index 0000000000000..eeb1b309257d4 --- /dev/null +++ b/src/librustc_data_structures/atomic_ref.rs @@ -0,0 +1,26 @@ +use std::marker::PhantomData; +use std::sync::atomic::{AtomicPtr, Ordering}; + +/// This is essentially an `AtomicPtr` but is guaranteed to always be valid +pub struct AtomicRef(AtomicPtr, PhantomData<&'static T>); + +impl AtomicRef { + pub const fn new(initial: &'static T) -> AtomicRef { + AtomicRef(AtomicPtr::new(initial as *const T as *mut T), PhantomData) + } + + pub fn swap(&self, new: &'static T) -> &'static T { + // We never allow storing anything but a `'static` reference so it's safe to + // return it for the same. + unsafe { &*self.0.swap(new as *const T as *mut T, Ordering::SeqCst) } + } +} + +impl std::ops::Deref for AtomicRef { + type Target = T; + fn deref(&self) -> &Self::Target { + // We never allow storing anything but a `'static` reference so it's safe to lend + // it out for any amount of time. + unsafe { &*self.0.load(Ordering::SeqCst) } + } +} diff --git a/src/librustc_data_structures/graph/iterate/mod.rs b/src/librustc_data_structures/graph/iterate/mod.rs index 53475cdf4ba42..d9d4c7e321fb5 100644 --- a/src/librustc_data_structures/graph/iterate/mod.rs +++ b/src/librustc_data_structures/graph/iterate/mod.rs @@ -101,14 +101,14 @@ pub enum ControlFlow { pub enum NodeStatus { /// This node has been examined by the depth-first search but is not yet `Settled`. /// - /// Also referred to as "gray" or "discovered" nodes in [CLR][]. + /// Also referred to as "gray" or "discovered" nodes in [CLR]. /// /// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms Visited, /// This node and all nodes reachable from it have been examined by the depth-first search. /// - /// Also referred to as "black" or "finished" nodes in [CLR][]. + /// Also referred to as "black" or "finished" nodes in [CLR]. /// /// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms Settled, @@ -122,13 +122,13 @@ struct Event { /// A depth-first search that also tracks when all successors of a node have been examined. /// /// This is based on the DFS described in [Introduction to Algorithms (1st ed.)][CLR], hereby -/// referred to as **CLR**. However, we use the terminology in [`NodeStatus`][] above instead of +/// referred to as **CLR**. However, we use the terminology in [`NodeStatus`] above instead of /// "discovered"/"finished" or "white"/"grey"/"black". Each node begins the search with no status, /// becomes `Visited` when it is first examined by the DFS and is `Settled` when all nodes /// reachable from it have been examined. This allows us to differentiate between "tree", "back" /// and "forward" edges (see [`TriColorVisitor::node_examined`]). /// -/// Unlike the pseudocode in [CLR][], this implementation is iterative and does not use timestamps. +/// Unlike the pseudocode in [CLR], this implementation is iterative and does not use timestamps. /// We accomplish this by storing `Event`s on the stack that result in a (possible) state change /// for each node. A `Visited` event signifies that we should examine this node if it has not yet /// been `Visited` or `Settled`. When a node is examined for the first time, we mark it as @@ -246,7 +246,7 @@ where /// By checking the value of `prior_status`, this visitor can determine whether the edge /// leading to this node was a tree edge (`None`), forward edge (`Some(Settled)`) or back edge /// (`Some(Visited)`). For a full explanation of each edge type, see the "Depth-first Search" - /// chapter in [CLR][] or [wikipedia][]. + /// chapter in [CLR] or [wikipedia]. /// /// If you want to know *both* nodes linked by each edge, you'll need to modify /// `TriColorDepthFirstSearch` to store a `source` node for each `Visited` event. diff --git a/src/librustc_data_structures/lib.rs b/src/librustc_data_structures/lib.rs index e035f39e34fd7..25bb8f6afae62 100644 --- a/src/librustc_data_structures/lib.rs +++ b/src/librustc_data_structures/lib.rs @@ -89,10 +89,12 @@ pub mod thin_vec; pub mod tiny_list; pub mod transitive_relation; pub use ena::unify; +mod atomic_ref; pub mod fingerprint; pub mod profiling; pub mod vec_linked_list; pub mod work_queue; +pub use atomic_ref::AtomicRef; pub struct OnDrop(pub F); diff --git a/src/librustc_errors/lib.rs b/src/librustc_errors/lib.rs index e93106b7adff1..53a673714a90a 100644 --- a/src/librustc_errors/lib.rs +++ b/src/librustc_errors/lib.rs @@ -17,11 +17,11 @@ use registry::Registry; use rustc_data_structures::fx::{FxHashSet, FxIndexMap}; use rustc_data_structures::stable_hasher::StableHasher; use rustc_data_structures::sync::{self, Lock, Lrc}; +use rustc_data_structures::AtomicRef; use syntax_pos::source_map::SourceMap; use syntax_pos::{Loc, MultiSpan, Span}; use std::borrow::Cow; -use std::cell::Cell; use std::panic; use std::path::Path; use std::{error, fmt}; @@ -309,8 +309,8 @@ pub enum StashKey { fn default_track_diagnostic(_: &Diagnostic) {} -thread_local!(pub static TRACK_DIAGNOSTICS: Cell = - Cell::new(default_track_diagnostic)); +pub static TRACK_DIAGNOSTICS: AtomicRef = + AtomicRef::new(&(default_track_diagnostic as fn(&_))); #[derive(Copy, Clone, Default)] pub struct HandlerFlags { @@ -730,9 +730,7 @@ impl HandlerInner { return; } - TRACK_DIAGNOSTICS.with(|track_diagnostics| { - track_diagnostics.get()(diagnostic); - }); + (*TRACK_DIAGNOSTICS)(diagnostic); if let Some(ref code) = diagnostic.code { self.emitted_diagnostic_codes.insert(code.clone()); diff --git a/src/librustc_interface/callbacks.rs b/src/librustc_interface/callbacks.rs new file mode 100644 index 0000000000000..28e687a378646 --- /dev/null +++ b/src/librustc_interface/callbacks.rs @@ -0,0 +1,48 @@ +//! Throughout the compiler tree, there are several places which want to have +//! access to state or queries while being inside crates that are dependencies +//! of librustc. To facilitate this, we have the +//! `rustc_data_structures::AtomicRef` type, which allows us to setup a global +//! static which can then be set in this file at program startup. +//! +//! See `SPAN_DEBUG` for an example of how to set things up. +//! +//! The functions in this file should fall back to the default set in their +//! origin crate when the `TyCtxt` is not present in TLS. + +use rustc::ty::tls; +use rustc_errors::{Diagnostic, TRACK_DIAGNOSTICS}; +use std::fmt; +use syntax_pos; + +/// This is a callback from libsyntax as it cannot access the implicit state +/// in librustc otherwise. +fn span_debug(span: syntax_pos::Span, f: &mut fmt::Formatter<'_>) -> fmt::Result { + tls::with_opt(|tcx| { + if let Some(tcx) = tcx { + write!(f, "{}", tcx.sess.source_map().span_to_string(span)) + } else { + syntax_pos::default_span_debug(span, f) + } + }) +} + +/// This is a callback from libsyntax as it cannot access the implicit state +/// in librustc otherwise. It is used to when diagnostic messages are +/// emitted and stores them in the current query, if there is one. +fn track_diagnostic(diagnostic: &Diagnostic) { + tls::with_context_opt(|icx| { + if let Some(icx) = icx { + if let Some(ref diagnostics) = icx.diagnostics { + let mut diagnostics = diagnostics.lock(); + diagnostics.extend(Some(diagnostic.clone())); + } + } + }) +} + +/// Sets up the callbacks in prior crates which we want to refer to the +/// TyCtxt in. +pub fn setup_callbacks() { + syntax_pos::SPAN_DEBUG.swap(&(span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); + TRACK_DIAGNOSTICS.swap(&(track_diagnostic as fn(&_))); +} diff --git a/src/librustc_interface/lib.rs b/src/librustc_interface/lib.rs index 3d79661978811..e4e6849ab8e59 100644 --- a/src/librustc_interface/lib.rs +++ b/src/librustc_interface/lib.rs @@ -11,6 +11,7 @@ #[cfg(unix)] extern crate libc; +mod callbacks; pub mod interface; mod passes; mod proc_macro_decls; diff --git a/src/librustc_interface/util.rs b/src/librustc_interface/util.rs index 1a2958a0a92c9..ccc2dcabec2c5 100644 --- a/src/librustc_interface/util.rs +++ b/src/librustc_interface/util.rs @@ -145,13 +145,15 @@ pub fn spawn_thread_pool R + Send, R: Send>( cfg = cfg.stack_size(size); } + crate::callbacks::setup_callbacks(); + scoped_thread(cfg, || { syntax::with_globals(edition, || { ty::tls::GCX_PTR.set(&Lock::new(0), || { if let Some(stderr) = stderr { io::set_panic(Some(box Sink(stderr.clone()))); } - ty::tls::with_thread_locals(|| f()) + f() }) }) }) @@ -167,6 +169,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( use rayon::{ThreadBuilder, ThreadPool, ThreadPoolBuilder}; let gcx_ptr = &Lock::new(0); + crate::callbacks::setup_callbacks(); let mut config = ThreadPoolBuilder::new() .thread_name(|_| "rustc".to_string()) @@ -194,9 +197,7 @@ pub fn spawn_thread_pool R + Send, R: Send>( if let Some(stderr) = stderr { io::set_panic(Some(box Sink(stderr.clone()))); } - ty::tls::with_thread_locals(|| { - ty::tls::GCX_PTR.set(gcx_ptr, || thread.run()) - }) + ty::tls::GCX_PTR.set(gcx_ptr, || thread.run()) }) }) }; diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 04f025fcbead9..e66708b173152 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -9,7 +9,7 @@ use rustc::mir::{ use rustc::ty::adjustment::PointerCast; use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashSet; -use rustc_errors::DiagnosticBuilder; +use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_index::vec::IndexVec; use syntax_pos::symbol::Symbol; use syntax_pos::Span; @@ -206,6 +206,47 @@ impl BorrowExplanation { ), ); }; + + self.add_lifetime_bound_suggestion_to_diagnostic( + tcx, + err, + &category, + span, + region_name, + ); + } + _ => {} + } + } + pub(in crate::borrow_check) fn add_lifetime_bound_suggestion_to_diagnostic<'tcx>( + &self, + tcx: TyCtxt<'tcx>, + err: &mut DiagnosticBuilder<'_>, + category: &ConstraintCategory, + span: Span, + region_name: &RegionName, + ) { + match category { + ConstraintCategory::OpaqueType => { + if let Ok(snippet) = tcx.sess.source_map().span_to_snippet(span) { + let suggestable_name = if region_name.was_named() { + region_name.to_string() + } else { + "'_".to_string() + }; + + err.span_suggestion( + span, + &format!( + "you can add a bound to the {}to make it last less than \ + `'static` and match `{}`", + category.description(), + region_name, + ), + format!("{} + {}", snippet, suggestable_name), + Applicability::Unspecified, + ); + } } _ => {} } diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index e61581336283c..a30b952bd0adb 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -840,7 +840,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { span, &format!( "to allow this `impl Trait` to capture borrowed data with lifetime \ - `{}`, add `{}` as a constraint", + `{}`, add `{}` as a bound", fr_name, suggestable_fr_name, ), format!("{} + {}", snippet, suggestable_fr_name), diff --git a/src/librustc_mir/dataflow/generic.rs b/src/librustc_mir/dataflow/generic.rs index 659ebeab65022..7eb6f5cc073df 100644 --- a/src/librustc_mir/dataflow/generic.rs +++ b/src/librustc_mir/dataflow/generic.rs @@ -10,7 +10,7 @@ //! interface, but make `Engine` and `ResultsCursor` the canonical way to perform and inspect a //! dataflow analysis. This requires porting the graphviz debugging logic to this module, deciding //! on a way to handle the `before` methods in `BitDenotation` and creating an adapter so that -//! gen-kill problems can still be evaluated efficiently. See the discussion in [#64566][] for more +//! gen-kill problems can still be evaluated efficiently. See the discussion in [#64566] for more //! information. //! //! [gk]: https://en.wikipedia.org/wiki/Data-flow_analysis#Bit_vector_problems diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index a6b30ab5e68cf..ab43249692cf4 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -20,7 +20,7 @@ use rustc::ty::layout::{ HasDataLayout, HasTyCtxt, LayoutError, LayoutOf, Size, TargetDataLayout, TyLayout, }; use rustc::ty::subst::InternalSubsts; -use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt}; +use rustc::ty::{self, Instance, ParamEnv, Ty, TyCtxt, TypeFoldable}; use rustc_data_structures::fx::FxHashMap; use rustc_index::vec::IndexVec; use syntax::ast::Mutability; @@ -410,6 +410,12 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } fn eval_constant(&mut self, c: &Constant<'tcx>) -> Option> { + // `eval_const_to_op` uses `Instance::resolve` which still has a bug (#66901) in the + // presence of trait items with a default body. So we just bail out if we aren't 100% + // monomorphic. + if c.literal.needs_subst() { + return None; + } self.ecx.tcx.span = c.span; match self.ecx.eval_const_to_op(c.literal, None) { Ok(op) => Some(op), @@ -556,6 +562,13 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { _ => {} } + // `eval_rvalue_into_place` uses `Instance::resolve` for constants which still has a bug + // (#66901) in the presence of trait items with a default body. So we just bail out if we + // aren't 100% monomorphic. + if rvalue.needs_subst() { + return None; + } + self.use_ecx(source_info, |this| { trace!("calling eval_rvalue_into_place(rvalue = {:?}, place = {:?})", rvalue, place); this.ecx.eval_rvalue_into_place(rvalue, place)?; diff --git a/src/librustc_target/abi/call/x86_win64.rs b/src/librustc_target/abi/call/x86_win64.rs index f08a7c5063e03..2aad641b1ecf0 100644 --- a/src/librustc_target/abi/call/x86_win64.rs +++ b/src/librustc_target/abi/call/x86_win64.rs @@ -1,7 +1,7 @@ use crate::abi::call::{ArgAbi, FnAbi, Reg}; use crate::abi::Abi; -// Win64 ABI: http://msdn.microsoft.com/en-us/library/zthk2dkh.aspx +// Win64 ABI: https://docs.microsoft.com/en-us/cpp/build/parameter-passing pub fn compute_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { let fixup = |a: &mut ArgAbi<'_, Ty>| { diff --git a/src/librustc_target/spec/i686_pc_windows_msvc.rs b/src/librustc_target/spec/i686_pc_windows_msvc.rs index 195c00d684f7d..b160007e0621a 100644 --- a/src/librustc_target/spec/i686_pc_windows_msvc.rs +++ b/src/librustc_target/spec/i686_pc_windows_msvc.rs @@ -11,7 +11,7 @@ pub fn target() -> TargetResult { // Ensure the linker will only produce an image if it can also produce a table of // the image's safe exception handlers. - // https://msdn.microsoft.com/en-us/library/9a89h429.aspx + // https://docs.microsoft.com/en-us/cpp/build/reference/safeseh-image-has-safe-exception-handlers base.pre_link_args.get_mut(&LinkerFlavor::Msvc).unwrap().push("/SAFESEH".to_string()); Ok(Target { diff --git a/src/librustc_typeck/check/pat.rs b/src/librustc_typeck/check/pat.rs index d0f1ef7b4ecd7..d80a17a048dc4 100644 --- a/src/librustc_typeck/check/pat.rs +++ b/src/librustc_typeck/check/pat.rs @@ -341,13 +341,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { fn check_pat_range( &self, span: Span, - begin: &'tcx hir::Expr, - end: &'tcx hir::Expr, + lhs: &'tcx hir::Expr, + rhs: &'tcx hir::Expr, expected: Ty<'tcx>, discrim_span: Option, ) -> Option> { - let lhs_ty = self.check_expr(begin); - let rhs_ty = self.check_expr(end); + let lhs_ty = self.check_expr(lhs); + let rhs_ty = self.check_expr(rhs); // Check that both end-points are of numeric or char type. let numeric_or_char = |ty: Ty<'_>| ty.is_numeric() || ty.is_char() || ty.references_error(); @@ -355,7 +355,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let rhs_fail = !numeric_or_char(rhs_ty); if lhs_fail || rhs_fail { - self.emit_err_pat_range(span, begin.span, end.span, lhs_fail, rhs_fail, lhs_ty, rhs_ty); + self.emit_err_pat_range(span, lhs.span, rhs.span, lhs_fail, rhs_fail, lhs_ty, rhs_ty); return None; } @@ -364,11 +364,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let common_type = self.resolve_vars_if_possible(&lhs_ty); // Subtyping doesn't matter here, as the value is some kind of scalar. - self.demand_eqtype_pat(span, expected, lhs_ty, discrim_span); - self.demand_eqtype_pat(span, expected, rhs_ty, discrim_span); + let demand_eqtype = |x_span, y_span, x_ty, y_ty| { + self.demand_eqtype_pat_diag(x_span, expected, x_ty, discrim_span).map(|mut err| { + self.endpoint_has_type(&mut err, y_span, y_ty); + err.emit(); + }); + }; + demand_eqtype(lhs.span, rhs.span, lhs_ty, rhs_ty); + demand_eqtype(rhs.span, lhs.span, rhs_ty, lhs_ty); + Some(common_type) } + fn endpoint_has_type(&self, err: &mut DiagnosticBuilder<'_>, span: Span, ty: Ty<'_>) { + if !ty.references_error() { + err.span_label(span, &format!("this is of type `{}`", ty)); + } + } + fn emit_err_pat_range( &self, span: Span, @@ -396,9 +409,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let msg = |ty| format!("this is of type `{}` but it should be `char` or numeric", ty); let mut one_side_err = |first_span, first_ty, second_span, second_ty: Ty<'_>| { err.span_label(first_span, &msg(first_ty)); - if !second_ty.references_error() { - err.span_label(second_span, &format!("this is of type `{}`", second_ty)); - } + self.endpoint_has_type(&mut err, second_span, second_ty); }; if lhs_fail && rhs_fail { err.span_label(begin_span, &msg(lhs_ty)); diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index a928867d9de93..fdc587ba5dacf 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1076,7 +1076,7 @@ impl<'a, K, V> IterMut<'a, K, V> { /// An owning iterator over the entries of a `HashMap`. /// -/// This `struct` is created by the [`into_iter`] method on [`HashMap`][`HashMap`] +/// This `struct` is created by the [`into_iter`] method on [`HashMap`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`into_iter`]: struct.HashMap.html#method.into_iter diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index fff64e9fc9008..566e5146cf857 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -1101,7 +1101,7 @@ pub struct Iter<'a, K: 'a> { /// An owning iterator over the items of a `HashSet`. /// -/// This `struct` is created by the [`into_iter`] method on [`HashSet`][`HashSet`] +/// This `struct` is created by the [`into_iter`] method on [`HashSet`] /// (provided by the `IntoIterator` trait). See its documentation for more. /// /// [`HashSet`]: struct.HashSet.html diff --git a/src/libstd/env.rs b/src/libstd/env.rs index 52eebcfcb94c0..60facd9f8d468 100644 --- a/src/libstd/env.rs +++ b/src/libstd/env.rs @@ -552,7 +552,7 @@ impl Error for JoinPathsError { /// (including to an empty string). /// - If both do not exist, [`GetUserProfileDirectory`][msdn] is used to return the path. /// -/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/bb762280(v=vs.85).aspx +/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/userenv/nf-userenv-getuserprofiledirectorya /// /// # Examples /// @@ -591,7 +591,7 @@ pub fn home_dir() -> Option { /// This behavior is identical to that of [`GetTempPath`][msdn], which this /// function uses internally. /// -/// [msdn]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992(v=vs.85).aspx +/// [msdn]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppatha /// /// ```no_run /// use std::env; diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 01e57ec0ab941..cff7bbe5ef183 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -1841,7 +1841,7 @@ pub fn read_link>(path: P) -> io::Result { /// or written to a file another application may read). /// /// [changes]: ../io/index.html#platform-specific-behavior -/// [path]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#maxpath +/// [path]: https://docs.microsoft.com/en-us/windows/win32/fileio/naming-a-file /// /// # Errors /// diff --git a/src/libstd/path.rs b/src/libstd/path.rs index 580ff1610ac83..f308d511cf850 100644 --- a/src/libstd/path.rs +++ b/src/libstd/path.rs @@ -2,7 +2,7 @@ //! Cross-platform path manipulation. //! -//! This module provides two types, [`PathBuf`] and [`Path`][`Path`] (akin to [`String`] +//! This module provides two types, [`PathBuf`] and [`Path`] (akin to [`String`] //! and [`str`]), for working with paths abstractly. These types are thin wrappers //! around [`OsString`] and [`OsStr`] respectively, meaning that they work directly //! on strings according to the local platform's path syntax. @@ -296,6 +296,13 @@ where } // See note at the top of this module to understand why these are used: +// +// These casts are safe as OsStr is internally a wrapper around [u8] on all +// platforms. +// +// Note that currently this relies on the special knowledge that libstd has; +// these types are single-element structs but are not marked repr(transparent) +// or repr(C) which would make these casts allowable outside std. fn os_str_as_u8_slice(s: &OsStr) -> &[u8] { unsafe { &*(s as *const OsStr as *const [u8]) } } diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index 0e334c191e7b9..e70204d6839fc 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -286,7 +286,7 @@ mod sync; mod cache_aligned; -/// The receiving half of Rust's [`channel`][] (or [`sync_channel`]) type. +/// The receiving half of Rust's [`channel`] (or [`sync_channel`]) type. /// This half can only be owned by one thread. /// /// Messages sent to the channel can be retrieved using [`recv`]. @@ -558,7 +558,7 @@ pub struct SendError(#[stable(feature = "rust1", since = "1.0.0")] pub T); /// An error returned from the [`recv`] function on a [`Receiver`]. /// /// The [`recv`] operation can only fail if the sending half of a -/// [`channel`][`channel`] (or [`sync_channel`]) is disconnected, implying that no further +/// [`channel`] (or [`sync_channel`]) is disconnected, implying that no further /// messages will ever be received. /// /// [`recv`]: struct.Receiver.html#method.recv @@ -1108,7 +1108,7 @@ impl Receiver { /// /// This function will always block the current thread if there is no data /// available and it's possible for more data to be sent. Once a message is - /// sent to the corresponding [`Sender`][] (or [`SyncSender`]), then this + /// sent to the corresponding [`Sender`] (or [`SyncSender`]), then this /// receiver will wake up and return that message. /// /// If the corresponding [`Sender`] has disconnected, or it disconnects while @@ -1194,7 +1194,7 @@ impl Receiver { /// /// This function will always block the current thread if there is no data /// available and it's possible for more data to be sent. Once a message is - /// sent to the corresponding [`Sender`][] (or [`SyncSender`]), then this + /// sent to the corresponding [`Sender`] (or [`SyncSender`]), then this /// receiver will wake up and return that message. /// /// If the corresponding [`Sender`] has disconnected, or it disconnects while @@ -1295,7 +1295,7 @@ impl Receiver { /// /// This function will always block the current thread if there is no data /// available and it's possible for more data to be sent. Once a message is - /// sent to the corresponding [`Sender`][] (or [`SyncSender`]), then this + /// sent to the corresponding [`Sender`] (or [`SyncSender`]), then this /// receiver will wake up and return that message. /// /// If the corresponding [`Sender`] has disconnected, or it disconnects while diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 2ff36133a7cef..fdd29af858185 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -25,7 +25,7 @@ use crate::sys_common::rwlock as sys; /// The type parameter `T` represents the data that this lock protects. It is /// required that `T` satisfies [`Send`] to be shared across threads and /// [`Sync`] to allow concurrent access through readers. The RAII guards -/// returned from the locking methods implement [`Deref`][] (and [`DerefMut`] +/// returned from the locking methods implement [`Deref`] (and [`DerefMut`] /// for the `write` methods) to allow access to the content of the lock. /// /// # Poisoning diff --git a/src/libstd/sys/windows/ext/fs.rs b/src/libstd/sys/windows/ext/fs.rs index 0462f889a8e54..d508a333484ae 100644 --- a/src/libstd/sys/windows/ext/fs.rs +++ b/src/libstd/sys/windows/ext/fs.rs @@ -117,7 +117,7 @@ pub trait OpenOptionsExt { /// let file = OpenOptions::new().access_mode(0).open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea #[stable(feature = "open_options_ext", since = "1.10.0")] fn access_mode(&mut self, access: u32) -> &mut Self; @@ -145,7 +145,7 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea #[stable(feature = "open_options_ext", since = "1.10.0")] fn share_mode(&mut self, val: u32) -> &mut Self; @@ -174,8 +174,8 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 #[stable(feature = "open_options_ext", since = "1.10.0")] fn custom_flags(&mut self, flags: u32) -> &mut Self; @@ -211,8 +211,8 @@ pub trait OpenOptionsExt { /// .open("foo.txt"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 #[stable(feature = "open_options_ext", since = "1.10.0")] fn attributes(&mut self, val: u32) -> &mut Self; @@ -254,10 +254,10 @@ pub trait OpenOptionsExt { /// .open(r"\\.\pipe\MyPipe"); /// ``` /// - /// [`CreateFile`]: https://msdn.microsoft.com/en-us/library/windows/desktop/aa363858.aspx - /// [`CreateFile2`]: https://msdn.microsoft.com/en-us/library/windows/desktop/hh449422.aspx + /// [`CreateFile`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea + /// [`CreateFile2`]: https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfile2 /// [Impersonation Levels]: - /// https://msdn.microsoft.com/en-us/library/windows/desktop/aa379572.aspx + /// https://docs.microsoft.com/en-us/windows/win32/api/winnt/ne-winnt-security_impersonation_level #[stable(feature = "open_options_ext", since = "1.10.0")] fn security_qos_flags(&mut self, flags: u32) -> &mut OpenOptions; } @@ -297,7 +297,7 @@ impl OpenOptionsExt for OpenOptions { /// /// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html /// [`BY_HANDLE_FILE_INFORMATION`]: -/// https://msdn.microsoft.com/en-us/library/windows/desktop/aa363788.aspx +/// https://docs.microsoft.com/en-us/windows/win32/api/fileapi/ns-fileapi-by_handle_file_information #[stable(feature = "metadata_ext", since = "1.1.0")] pub trait MetadataExt { /// Returns the value of the `dwFileAttributes` field of this metadata. @@ -321,7 +321,7 @@ pub trait MetadataExt { /// ``` /// /// [File Attribute Constants]: - /// https://msdn.microsoft.com/en-us/library/windows/desktop/gg258117.aspx + /// https://docs.microsoft.com/en-us/windows/win32/fileio/file-attribute-constants #[stable(feature = "metadata_ext", since = "1.1.0")] fn file_attributes(&self) -> u32; @@ -350,7 +350,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn creation_time(&self) -> u64; @@ -385,7 +385,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_access_time(&self) -> u64; @@ -418,7 +418,7 @@ pub trait MetadataExt { /// } /// ``` /// - /// [`FILETIME`]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724284.aspx + /// [`FILETIME`]: https://docs.microsoft.com/en-us/windows/win32/api/minwinbase/ns-minwinbase-filetime #[stable(feature = "metadata_ext", since = "1.1.0")] fn last_write_time(&self) -> u64; diff --git a/src/libstd/sys/windows/ext/process.rs b/src/libstd/sys/windows/ext/process.rs index ed35c5ff19446..8c34a9faf1d4a 100644 --- a/src/libstd/sys/windows/ext/process.rs +++ b/src/libstd/sys/windows/ext/process.rs @@ -99,7 +99,7 @@ pub trait CommandExt { /// /// These will always be ORed with `CREATE_UNICODE_ENVIRONMENT`. /// - /// [1]: https://msdn.microsoft.com/en-us/library/windows/desktop/ms684863(v=vs.85).aspx + /// [1]: https://docs.microsoft.com/en-us/windows/win32/procthread/process-creation-flags #[stable(feature = "windows_process_extensions", since = "1.16.0")] fn creation_flags(&mut self, flags: u32) -> &mut process::Command; } diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index a515b382ab02a..b004cd19020f8 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -262,7 +262,7 @@ pub fn dur2timeout(dur: Duration) -> c::DWORD { // terminating the process but without necessarily bypassing all exception // handlers. // -// https://msdn.microsoft.com/en-us/library/dn774154.aspx +// https://docs.microsoft.com/en-us/cpp/intrinsics/fastfail #[allow(unreachable_code)] pub unsafe fn abort_internal() -> ! { #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index e0a1d2f4c0e20..e7fa61dd0f6b9 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -34,7 +34,7 @@ pub fn error_string(mut errnum: i32) -> String { // NTSTATUS errors may be encoded as HRESULT, which may returned from // GetLastError. For more information about Windows error codes, see - // `[MS-ERREF]`: https://msdn.microsoft.com/en-us/library/cc231198.aspx + // `[MS-ERREF]`: https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/0642cb2f-2075-4469-918c-4441e69c548a if (errnum & c::FACILITY_NT_BIT as i32) != 0 { // format according to https://support.microsoft.com/en-us/help/259693 const NTDLL_DLL: &[u16] = &[ diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 4af552c65617e..a58c12f23508a 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -13,6 +13,7 @@ #![feature(specialization)] #![feature(step_trait)] +use rustc_data_structures::AtomicRef; use rustc_macros::HashStable_Generic; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; @@ -41,7 +42,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::{Lock, Lrc}; use std::borrow::Cow; -use std::cell::{Cell, RefCell}; +use std::cell::RefCell; use std::cmp::{self, Ordering}; use std::fmt; use std::hash::{Hash, Hasher}; @@ -665,13 +666,13 @@ pub fn default_span_debug(span: Span, f: &mut fmt::Formatter<'_>) -> fmt::Result impl fmt::Debug for Span { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - SPAN_DEBUG.with(|span_debug| span_debug.get()(*self, f)) + (*SPAN_DEBUG)(*self, f) } } impl fmt::Debug for SpanData { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - SPAN_DEBUG.with(|span_debug| span_debug.get()(Span::new(self.lo, self.hi, self.ctxt), f)) + (*SPAN_DEBUG)(Span::new(self.lo, self.hi, self.ctxt), f) } } @@ -1503,8 +1504,8 @@ pub struct FileLines { pub lines: Vec, } -thread_local!(pub static SPAN_DEBUG: Cell) -> fmt::Result> = - Cell::new(default_span_debug)); +pub static SPAN_DEBUG: AtomicRef) -> fmt::Result> = + AtomicRef::new(&(default_span_debug as fn(_, &mut fmt::Formatter<'_>) -> _)); #[derive(Debug)] pub struct MacroBacktrace { diff --git a/src/libterm/lib.rs b/src/libterm/lib.rs index 7318ced676a4c..d2e3b07ab855d 100644 --- a/src/libterm/lib.rs +++ b/src/libterm/lib.rs @@ -27,7 +27,7 @@ //! ``` //! //! [ansi]: https://en.wikipedia.org/wiki/ANSI_escape_code -//! [win]: http://msdn.microsoft.com/en-us/library/windows/desktop/ms682010%28v=vs.85%29.aspx +//! [win]: https://docs.microsoft.com/en-us/windows/console/character-mode-applications //! [ti]: https://en.wikipedia.org/wiki/Terminfo #![doc( diff --git a/src/libterm/win.rs b/src/libterm/win.rs index a789d739ab174..b6c607a30816c 100644 --- a/src/libterm/win.rs +++ b/src/libterm/win.rs @@ -101,7 +101,7 @@ impl WinConsole { unsafe { // Magic -11 means stdout, from - // http://msdn.microsoft.com/en-us/library/windows/desktop/ms683231%28v=vs.85%29.aspx + // https://docs.microsoft.com/en-us/windows/console/getstdhandle // // You may be wondering, "but what about stderr?", and the answer // to that is that setting terminal attributes on the stdout diff --git a/src/test/ui/error-codes/E0308-4.stderr b/src/test/ui/error-codes/E0308-4.stderr index 127fdaadbc5dd..46805d6e13b7c 100644 --- a/src/test/ui/error-codes/E0308-4.stderr +++ b/src/test/ui/error-codes/E0308-4.stderr @@ -1,10 +1,12 @@ error[E0308]: mismatched types - --> $DIR/E0308-4.rs:4:9 + --> $DIR/E0308-4.rs:4:15 | LL | match x { | - this match expression has type `u8` LL | 0u8..=3i8 => (), - | ^^^^^^^^^ expected `u8`, found `i8` + | --- ^^^ expected `u8`, found `i8` + | | + | this is of type `u8` error: aborting due to previous error diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr index 2029cfaf75dfe..04538cd74b195 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision.stderr @@ -10,7 +10,7 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [_, 99.., _] => {}, - | ^^^^ expected struct `std::ops::Range`, found integer + | ^^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr index 6a88d05837a87..c918d0a385c75 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision2.stderr @@ -16,7 +16,7 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [_, 99..] => {}, - | ^^^^ expected struct `std::ops::Range`, found integer + | ^^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs index 95e58b1d48c88..1557f592b2a9b 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.rs @@ -6,6 +6,7 @@ fn main() { //~^ ERROR `..X` range patterns are not supported //~| ERROR mismatched types //~| ERROR mismatched types + //~| ERROR mismatched types _ => {}, } } diff --git a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr index 5c49fbe4c5c94..e6ee3817b3558 100644 --- a/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr +++ b/src/test/ui/exclusive-range/exclusive_range_pattern_syntax_collision3.stderr @@ -5,12 +5,12 @@ LL | [..9, 99..100, _] => {}, | ^^^ help: try using the minimum value for the type: `MIN..9` error[E0308]: mismatched types - --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:10 + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:12 | LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [..9, 99..100, _] => {}, - | ^^^ expected struct `std::ops::Range`, found integer + | ^ expected struct `std::ops::Range`, found integer | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` @@ -21,11 +21,26 @@ error[E0308]: mismatched types LL | match [5..4, 99..105, 43..44] { | ----------------------- this match expression has type `std::ops::Range<{integer}>` LL | [..9, 99..100, _] => {}, - | ^^^^^^^ expected struct `std::ops::Range`, found integer + | ^^ --- this is of type `{integer}` + | | + | expected struct `std::ops::Range`, found integer + | + = note: expected struct `std::ops::Range<{integer}>` + found type `{integer}` + +error[E0308]: mismatched types + --> $DIR/exclusive_range_pattern_syntax_collision3.rs:5:19 + | +LL | match [5..4, 99..105, 43..44] { + | ----------------------- this match expression has type `std::ops::Range<{integer}>` +LL | [..9, 99..100, _] => {}, + | -- ^^^ expected struct `std::ops::Range`, found integer + | | + | this is of type `{integer}` | = note: expected struct `std::ops::Range<{integer}>` found type `{integer}` -error: aborting due to 3 previous errors +error: aborting due to 4 previous errors For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.rs b/src/test/ui/impl-trait/does-not-live-long-enough.rs new file mode 100644 index 0000000000000..6179132b3f608 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.rs @@ -0,0 +1,11 @@ +struct List { + data: Vec, +} +impl List { + fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + //~^ ERROR does not live long enough + } +} + +fn main() {} diff --git a/src/test/ui/impl-trait/does-not-live-long-enough.stderr b/src/test/ui/impl-trait/does-not-live-long-enough.stderr new file mode 100644 index 0000000000000..83d0f87015bf9 --- /dev/null +++ b/src/test/ui/impl-trait/does-not-live-long-enough.stderr @@ -0,0 +1,21 @@ +error[E0597]: `prefix` does not live long enough + --> $DIR/does-not-live-long-enough.rs:6:51 + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator { + | -- lifetime `'a` defined here --------------------------- opaque type requires that `prefix` is borrowed for `'a` +LL | self.data.iter().filter(|s| s.starts_with(prefix)).map(|s| s.as_ref()) + | --- ^^^^^^ borrowed value does not live long enough + | | + | value captured here +LL | +LL | } + | - `prefix` dropped here while still borrowed + | +help: you can add a bound to the opaque type to make it last less than `'static` and match `'a` + | +LL | fn started_with<'a>(&'a self, prefix: &'a str) -> impl Iterator + 'a { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 45c5142d93f28..4c38f0a8a914d 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -5,7 +5,7 @@ LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { | -- lifetime `'a` defined here ^^^^^^^^^ opaque type requires that `'a` must outlive `'static` | = help: consider replacing `'a` with `'static` -help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a constraint +help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | LL | type E<'a, 'b> = impl Sized; + 'a | diff --git a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr index a8341f62e1d14..7f92e709af556 100644 --- a/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr +++ b/src/test/ui/impl-trait/must_outlive_least_region_or_bound.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the function body at | LL | fn elided(x: &i32) -> impl Copy { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 | LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ^^^^^^^^^^^^^^ @@ -29,7 +29,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 6:13 | LL | fn explicit<'a>(x: &'a i32) -> impl Copy + 'a { x } | ^^^^^^^^^^^^^^ @@ -47,7 +47,7 @@ note: ...can't outlive the lifetime `'a` as defined on the function body at 12:1 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static { x } | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the function body at 12:15 | LL | fn with_bound<'a>(x: &'a i32) -> impl LifetimeTrait<'a> + 'static + 'a { x } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr index 1d6b5f56aa0cf..e550be1917474 100644 --- a/src/test/ui/impl-trait/static-return-lifetime-infered.stderr +++ b/src/test/ui/impl-trait/static-return-lifetime-infered.stderr @@ -15,7 +15,7 @@ LL | / fn iter_values_anon(&self) -> impl Iterator { LL | | self.x.iter().map(|a| a.0) LL | | } | |_____^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 6:5 | LL | fn iter_values_anon(&self) -> impl Iterator + '_ { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -35,7 +35,7 @@ note: ...can't outlive the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator { | ^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 +help: you can add a bound to the return type to make it last less than `'static` and match the lifetime `'a` as defined on the method body at 10:20 | LL | fn iter_values<'a>(&'a self) -> impl Iterator + 'a { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/test/ui/match/match-range-fail.stderr b/src/test/ui/match/match-range-fail.stderr index adaaf29aae4c8..64105dc73d3f5 100644 --- a/src/test/ui/match/match-range-fail.stderr +++ b/src/test/ui/match/match-range-fail.stderr @@ -28,7 +28,9 @@ error[E0308]: mismatched types --> $DIR/match-range-fail.rs:18:9 | LL | 'c' ..= 100 => { } - | ^^^^^^^^^^^ expected integer, found `char` + | ^^^ --- this is of type `{integer}` + | | + | expected integer, found `char` error: aborting due to 4 previous errors diff --git a/src/test/ui/parser/pat-tuple-5.stderr b/src/test/ui/parser/pat-tuple-5.stderr index 3579a2c4e0951..5b0253cd2738a 100644 --- a/src/test/ui/parser/pat-tuple-5.stderr +++ b/src/test/ui/parser/pat-tuple-5.stderr @@ -19,7 +19,7 @@ error[E0308]: mismatched types LL | match (0, 1) { | ------ this match expression has type `({integer}, {integer})` LL | (PAT ..) => {} - | ^^^^^^ expected tuple, found `u8` + | ^^^ expected tuple, found `u8` | = note: expected tuple `({integer}, {integer})` found type `u8` diff --git a/src/test/ui/parser/recover-range-pats.stderr b/src/test/ui/parser/recover-range-pats.stderr index af03b577548f7..50a44192707f0 100644 --- a/src/test/ui/parser/recover-range-pats.stderr +++ b/src/test/ui/parser/recover-range-pats.stderr @@ -417,13 +417,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:21:12 | LL | if let .0..Y = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:23:12 + --> $DIR/recover-range-pats.rs:23:16 | LL | if let X.. .0 = 0 {} - | ^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:32:12 @@ -445,13 +449,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:34:12 | LL | if let .0..=Y = 0 {} - | ^^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:36:12 + --> $DIR/recover-range-pats.rs:36:16 | LL | if let X..=.0 = 0 {} - | ^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:45:12 @@ -473,13 +481,17 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:49:12 | LL | if let .0...Y = 0 {} - | ^^^^^^ expected integer, found floating-point number + | ^^ - this is of type `u8` + | | + | expected integer, found floating-point number error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:52:12 + --> $DIR/recover-range-pats.rs:52:17 | LL | if let X... .0 = 0 {} - | ^^^^^^^ expected integer, found floating-point number + | - ^^ expected integer, found floating-point number + | | + | this is of type `u8` error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:60:12 @@ -491,7 +503,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:62:12 | LL | if let .0.. = 0 {} - | ^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:70:12 @@ -503,7 +515,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:72:12 | LL | if let .0..= = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:82:12 @@ -515,7 +527,7 @@ error[E0308]: mismatched types --> $DIR/recover-range-pats.rs:85:12 | LL | if let .0... = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:94:14 @@ -524,10 +536,10 @@ LL | if let ..true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:96:12 + --> $DIR/recover-range-pats.rs:96:15 | LL | if let .. .0 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:104:15 @@ -536,10 +548,10 @@ LL | if let ..=true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:106:12 + --> $DIR/recover-range-pats.rs:106:15 | LL | if let ..=.0 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error[E0029]: only char and numeric types are allowed in range patterns --> $DIR/recover-range-pats.rs:116:15 @@ -548,10 +560,10 @@ LL | if let ...true = 0 {} | ^^^^ this is of type `bool` but it should be `char` or numeric error[E0308]: mismatched types - --> $DIR/recover-range-pats.rs:119:12 + --> $DIR/recover-range-pats.rs:119:15 | LL | if let ....3 = 0 {} - | ^^^^^ expected integer, found floating-point number + | ^^ expected integer, found floating-point number error: aborting due to 85 previous errors diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr index 5118280e7ec0c..9f5414995151b 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_impl_trait.stderr @@ -11,7 +11,7 @@ note: ...can't outlive the anonymous lifetime #1 defined on the method body at 8 | LL | fn f(self: Pin<&Self>) -> impl Clone { self } | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 +help: you can add a bound to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the method body at 8:5 | LL | fn f(self: Pin<&Self>) -> impl Clone + '_ { self } | ^^^^^^^^^^^^^^^ diff --git a/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557-ice.rs b/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557-ice.rs new file mode 100644 index 0000000000000..4c09ae25c5f3e --- /dev/null +++ b/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557-ice.rs @@ -0,0 +1,25 @@ +// This used to cause an ICE for an internal index out of range due to simd_shuffle_indices being +// passed the wrong Instance, causing issues with inlining. See #67557. +// +// run-pass +// compile-flags: -Zmir-opt-level=3 +#![feature(platform_intrinsics, repr_simd)] + +extern "platform-intrinsic" { + fn simd_shuffle2(x: T, y: T, idx: [u32; 2]) -> U; +} + +#[repr(simd)] +#[derive(Debug, PartialEq)] +struct Simd2(u8, u8); + +fn main() { + unsafe { + let _: Simd2 = inline_me(); + } +} + +#[inline(always)] +unsafe fn inline_me() -> Simd2 { + simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 3]) +} diff --git a/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557.rs b/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557.rs new file mode 100644 index 0000000000000..7a0d955686bb6 --- /dev/null +++ b/src/test/ui/simd-intrinsic/simd-intrinsic-inlining-issue67557.rs @@ -0,0 +1,40 @@ +// This used to cause assert_10_13 to unexpectingly fail, due to simd_shuffle_indices being passed +// the wrong Instance, causing issues with inlining. See #67557. +// +// run-pass +// compile-flags: -Zmir-opt-level=3 +#![feature(platform_intrinsics, repr_simd)] + +extern "platform-intrinsic" { + fn simd_shuffle2(x: T, y: T, idx: [u32; 2]) -> U; +} + +#[repr(simd)] +#[derive(Debug, PartialEq)] +struct Simd2(u8, u8); + +fn main() { + unsafe { + let p_res: Simd2 = simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 1]); + let a_res: Simd2 = inline_me(); + + assert_10_11(p_res); + assert_10_13(a_res); + } +} + +#[inline(never)] +fn assert_10_11(x: Simd2) { + assert_eq!(x, Simd2(10, 11)); +} + +#[inline(never)] +fn assert_10_13(x: Simd2) { + assert_eq!(x, Simd2(10, 13)); +} + + +#[inline(always)] +unsafe fn inline_me() -> Simd2 { + simd_shuffle2(Simd2(10, 11), Simd2(12, 13), [0, 3]) +}