| author | bors <bors@rust-lang.org> 2026-05-24 06:29:32 UTC |
| committer | bors <bors@rust-lang.org> 2026-05-24 06:29:32 UTC |
| log | 06b13d50ca813d84d93fcddbaaef069011b16fbb |
| tree | 49824ffbdc0299eb0cbfdda80ccbdbb3218157e6 |
| parent | e1ff77d89857bfbf7ce8eefe09b450a7ed5c67ca |
| parent | 28436418fa73de65fe3c1b04d80451066223b87a |
Rollup of 6 pull requests
Successful merges:
- rust-lang/rust#156769 (Use print instead of po in debuginfo path test)
- rust-lang/rust#156784 (Fix reborrow_info early return skipping field validation)
- rust-lang/rust#156827 (float_literal_f32_fallback: Don't suggest invalid code)
- rust-lang/rust#156828 (Add unstable Share trait)
- rust-lang/rust#156830 (Add `#[doc(alias = "phi")]` for float `GOLDEN_RATIO` constants)
- rust-lang/rust#156860 (Fix Pieter-Louis Schoeman mailmap entry)35 files changed, 542 insertions(+), 14 deletions(-)
.mailmap+1| ... | @@ -569,6 +569,7 @@ Philipp Matthias Schäfer <philipp.matthias.schaefer@posteo.de> | ... | @@ -569,6 +569,7 @@ Philipp Matthias Schäfer <philipp.matthias.schaefer@posteo.de> |
| 569 | phosphorus <steepout@qq.com> | 569 | phosphorus <steepout@qq.com> |
| 570 | Pierre Krieger <pierre.krieger1708@gmail.com> | 570 | Pierre Krieger <pierre.krieger1708@gmail.com> |
| 571 | pierwill <pierwill@users.noreply.github.com> <19642016+pierwill@users.noreply.github.com> | 571 | pierwill <pierwill@users.noreply.github.com> <19642016+pierwill@users.noreply.github.com> |
| 572 | Pieter-Louis Schoeman <pl.schoeman44@gmail.com> <127837395+P8L1@users.noreply.github.com> | ||
| 572 | Pietro Albini <pietro@pietroalbini.org> <pietro@pietroalbini.io> | 573 | Pietro Albini <pietro@pietroalbini.org> <pietro@pietroalbini.io> |
| 573 | Pietro Albini <pietro@pietroalbini.org> <pietro.albini@ferrous-systems.com> | 574 | Pietro Albini <pietro@pietroalbini.org> <pietro.albini@ferrous-systems.com> |
| 574 | Pradyumna Rahul <prkinformed@gmail.com> | 575 | Pradyumna Rahul <prkinformed@gmail.com> |
compiler/rustc_hir_analysis/src/coherence/builtin.rs+2-2| ... | @@ -563,8 +563,8 @@ pub(crate) fn reborrow_info<'tcx>( | ... | @@ -563,8 +563,8 @@ pub(crate) fn reborrow_info<'tcx>( |
| 563 | ) | 563 | ) |
| 564 | .is_ok() | 564 | .is_ok() |
| 565 | { | 565 | { |
| 566 | // Field implements Reborrow. | 566 | // Field implements Reborrow, check remaining fields. |
| 567 | return Ok(()); | 567 | continue; |
| 568 | } | 568 | } |
| 569 | 569 | ||
| 570 | // Field does not implement Reborrow: it must be Copy. | 570 | // Field does not implement Reborrow: it must be Copy. |
compiler/rustc_hir_typeck/src/fallback.rs+7-1| ... | @@ -171,7 +171,13 @@ impl<'tcx> FnCtxt<'_, 'tcx> { | ... | @@ -171,7 +171,13 @@ impl<'tcx> FnCtxt<'_, 'tcx> { |
| 171 | .inspect(|vid| { | 171 | .inspect(|vid| { |
| 172 | let origin = self.float_var_origin(*vid); | 172 | let origin = self.float_var_origin(*vid); |
| 173 | // Show the entire literal in the suggestion to make it clearer. | 173 | // Show the entire literal in the suggestion to make it clearer. |
| 174 | let literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok(); | 174 | let mut literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok(); |
| 175 | // A `.` at the end of the literal is no longer necessary if `f32` is explicitly specified | ||
| 176 | if let Some(ref mut literal) = literal | ||
| 177 | && literal.ends_with('.') | ||
| 178 | { | ||
| 179 | literal.pop(); | ||
| 180 | } | ||
| 175 | self.tcx.emit_node_span_lint( | 181 | self.tcx.emit_node_span_lint( |
| 176 | FLOAT_LITERAL_F32_FALLBACK, | 182 | FLOAT_LITERAL_F32_FALLBACK, |
| 177 | origin.lint_id.unwrap_or(CRATE_HIR_ID), | 183 | origin.lint_id.unwrap_or(CRATE_HIR_ID), |
library/alloc/src/lib.rs+1| ... | @@ -144,6 +144,7 @@ | ... | @@ -144,6 +144,7 @@ |
| 144 | #![feature(ptr_metadata)] | 144 | #![feature(ptr_metadata)] |
| 145 | #![feature(rev_into_inner)] | 145 | #![feature(rev_into_inner)] |
| 146 | #![feature(set_ptr_value)] | 146 | #![feature(set_ptr_value)] |
| 147 | #![feature(share_trait)] | ||
| 147 | #![feature(sized_type_properties)] | 148 | #![feature(sized_type_properties)] |
| 148 | #![feature(slice_from_ptr_range)] | 149 | #![feature(slice_from_ptr_range)] |
| 149 | #![feature(slice_index_methods)] | 150 | #![feature(slice_index_methods)] |
library/alloc/src/rc.rs+4-1| ... | @@ -245,7 +245,7 @@ use core::any::Any; | ... | @@ -245,7 +245,7 @@ use core::any::Any; |
| 245 | use core::cell::{Cell, CloneFromCell}; | 245 | use core::cell::{Cell, CloneFromCell}; |
| 246 | #[cfg(not(no_global_oom_handling))] | 246 | #[cfg(not(no_global_oom_handling))] |
| 247 | use core::clone::TrivialClone; | 247 | use core::clone::TrivialClone; |
| 248 | use core::clone::{CloneToUninit, UseCloned}; | 248 | use core::clone::{CloneToUninit, Share, UseCloned}; |
| 249 | use core::cmp::Ordering; | 249 | use core::cmp::Ordering; |
| 250 | use core::hash::{Hash, Hasher}; | 250 | use core::hash::{Hash, Hasher}; |
| 251 | use core::intrinsics::abort; | 251 | use core::intrinsics::abort; |
| ... | @@ -2525,6 +2525,9 @@ impl<T: ?Sized, A: Allocator + Clone> Clone for Rc<T, A> { | ... | @@ -2525,6 +2525,9 @@ impl<T: ?Sized, A: Allocator + Clone> Clone for Rc<T, A> { |
| 2525 | #[unstable(feature = "ergonomic_clones", issue = "132290")] | 2525 | #[unstable(feature = "ergonomic_clones", issue = "132290")] |
| 2526 | impl<T: ?Sized, A: Allocator + Clone> UseCloned for Rc<T, A> {} | 2526 | impl<T: ?Sized, A: Allocator + Clone> UseCloned for Rc<T, A> {} |
| 2527 | 2527 | ||
| 2528 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 2529 | impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A> {} | ||
| 2530 | |||
| 2528 | #[cfg(not(no_global_oom_handling))] | 2531 | #[cfg(not(no_global_oom_handling))] |
| 2529 | #[stable(feature = "rust1", since = "1.0.0")] | 2532 | #[stable(feature = "rust1", since = "1.0.0")] |
| 2530 | impl<T: Default> Default for Rc<T> { | 2533 | impl<T: Default> Default for Rc<T> { |
library/alloc/src/sync.rs+4-1| ... | @@ -12,7 +12,7 @@ use core::any::Any; | ... | @@ -12,7 +12,7 @@ use core::any::Any; |
| 12 | use core::cell::CloneFromCell; | 12 | use core::cell::CloneFromCell; |
| 13 | #[cfg(not(no_global_oom_handling))] | 13 | #[cfg(not(no_global_oom_handling))] |
| 14 | use core::clone::TrivialClone; | 14 | use core::clone::TrivialClone; |
| 15 | use core::clone::{CloneToUninit, UseCloned}; | 15 | use core::clone::{CloneToUninit, Share, UseCloned}; |
| 16 | use core::cmp::Ordering; | 16 | use core::cmp::Ordering; |
| 17 | use core::hash::{Hash, Hasher}; | 17 | use core::hash::{Hash, Hasher}; |
| 18 | use core::intrinsics::abort; | 18 | use core::intrinsics::abort; |
| ... | @@ -2436,6 +2436,9 @@ impl<T: ?Sized, A: Allocator + Clone> Clone for Arc<T, A> { | ... | @@ -2436,6 +2436,9 @@ impl<T: ?Sized, A: Allocator + Clone> Clone for Arc<T, A> { |
| 2436 | #[unstable(feature = "ergonomic_clones", issue = "132290")] | 2436 | #[unstable(feature = "ergonomic_clones", issue = "132290")] |
| 2437 | impl<T: ?Sized, A: Allocator + Clone> UseCloned for Arc<T, A> {} | 2437 | impl<T: ?Sized, A: Allocator + Clone> UseCloned for Arc<T, A> {} |
| 2438 | 2438 | ||
| 2439 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 2440 | impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A> {} | ||
| 2441 | |||
| 2439 | #[stable(feature = "rust1", since = "1.0.0")] | 2442 | #[stable(feature = "rust1", since = "1.0.0")] |
| 2440 | impl<T: ?Sized, A: Allocator> Deref for Arc<T, A> { | 2443 | impl<T: ?Sized, A: Allocator> Deref for Arc<T, A> { |
| 2441 | type Target = T; | 2444 | type Target = T; |
library/core/src/clone.rs+88-1| ... | @@ -290,6 +290,90 @@ pub macro Clone($item:item) { | ... | @@ -290,6 +290,90 @@ pub macro Clone($item:item) { |
| 290 | /* compiler built-in */ | 290 | /* compiler built-in */ |
| 291 | } | 291 | } |
| 292 | 292 | ||
| 293 | /// A trait for types whose [`Clone`] operation creates another alias to the same | ||
| 294 | /// logical resource or shared state. | ||
| 295 | /// | ||
| 296 | /// `Share` marks types where cloning creates another handle, reference, or alias | ||
| 297 | /// to the same logical resource or shared state, rather than an independent owned | ||
| 298 | /// value. The distinction is semantic, not cost-based: implementing `Share` does | ||
| 299 | /// not merely mean that cloning is cheap, constant-time, allocation-free, or | ||
| 300 | /// convenient. | ||
| 301 | /// | ||
| 302 | /// Calling [`share`](Share::share) is equivalent to calling [`clone`](Clone::clone) | ||
| 303 | /// for implementors, but communicates that the resulting value aliases the same | ||
| 304 | /// underlying resource. | ||
| 305 | /// | ||
| 306 | /// Shared references, `Rc<T>`, `Arc<T>`, `Sender<T>`, and `SyncSender<T>` are | ||
| 307 | /// examples of types that can be shared this way. Types such as `Vec<T>`, | ||
| 308 | /// `String`, and `Box<T>` are not `Share` even though they implement `Clone`, | ||
| 309 | /// because cloning them creates another owned value rather than another handle | ||
| 310 | /// to the same logical resource. | ||
| 311 | /// | ||
| 312 | /// # Examples | ||
| 313 | /// | ||
| 314 | /// ``` | ||
| 315 | /// #![feature(share_trait)] | ||
| 316 | /// | ||
| 317 | /// use std::cell::Cell; | ||
| 318 | /// use std::clone::Share; | ||
| 319 | /// use std::rc::Rc; | ||
| 320 | /// use std::sync::{ | ||
| 321 | /// Arc, | ||
| 322 | /// atomic::{AtomicUsize, Ordering}, | ||
| 323 | /// }; | ||
| 324 | /// | ||
| 325 | /// let value = 1; | ||
| 326 | /// let reference = &value; | ||
| 327 | /// assert!(std::ptr::eq(reference, reference.share())); | ||
| 328 | /// | ||
| 329 | /// let rc = Rc::new(Cell::new(2)); | ||
| 330 | /// let shared_rc = rc.share(); | ||
| 331 | /// assert!(Rc::ptr_eq(&rc, &shared_rc)); | ||
| 332 | /// shared_rc.set(3); | ||
| 333 | /// assert_eq!(rc.get(), 3); | ||
| 334 | /// | ||
| 335 | /// let arc = Arc::new(AtomicUsize::new(4)); | ||
| 336 | /// let shared_arc = arc.share(); | ||
| 337 | /// assert!(Arc::ptr_eq(&arc, &shared_arc)); | ||
| 338 | /// shared_arc.store(5, Ordering::Relaxed); | ||
| 339 | /// assert_eq!(arc.load(Ordering::Relaxed), 5); | ||
| 340 | /// ``` | ||
| 341 | /// | ||
| 342 | /// ``` | ||
| 343 | /// #![feature(share_trait)] | ||
| 344 | /// | ||
| 345 | /// use std::clone::Share; | ||
| 346 | /// use std::sync::mpsc::{channel, sync_channel}; | ||
| 347 | /// | ||
| 348 | /// let (sender, receiver) = channel(); | ||
| 349 | /// let shared_sender = sender.share(); | ||
| 350 | /// sender.send(1).unwrap(); | ||
| 351 | /// shared_sender.send(2).unwrap(); | ||
| 352 | /// | ||
| 353 | /// let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()]; | ||
| 354 | /// received.sort(); | ||
| 355 | /// assert_eq!(received, [1, 2]); | ||
| 356 | /// | ||
| 357 | /// let (sync_sender, sync_receiver) = sync_channel(2); | ||
| 358 | /// let shared_sync_sender = sync_sender.share(); | ||
| 359 | /// sync_sender.send(3).unwrap(); | ||
| 360 | /// shared_sync_sender.send(4).unwrap(); | ||
| 361 | /// | ||
| 362 | /// let mut received = [sync_receiver.recv().unwrap(), sync_receiver.recv().unwrap()]; | ||
| 363 | /// received.sort(); | ||
| 364 | /// assert_eq!(received, [3, 4]); | ||
| 365 | /// ``` | ||
| 366 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 367 | pub trait Share: Clone { | ||
| 368 | /// Creates another alias to the same underlying resource or shared state. | ||
| 369 | /// | ||
| 370 | /// This is equivalent to calling [`Clone::clone`]. | ||
| 371 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 372 | fn share(&self) -> Self { | ||
| 373 | Clone::clone(self) | ||
| 374 | } | ||
| 375 | } | ||
| 376 | |||
| 293 | /// Trait for objects whose [`Clone`] impl is lightweight (e.g. reference-counted) | 377 | /// Trait for objects whose [`Clone`] impl is lightweight (e.g. reference-counted) |
| 294 | /// | 378 | /// |
| 295 | /// Cloning an object implementing this trait should in general: | 379 | /// Cloning an object implementing this trait should in general: |
| ... | @@ -601,7 +685,7 @@ unsafe impl CloneToUninit for crate::bstr::ByteStr { | ... | @@ -601,7 +685,7 @@ unsafe impl CloneToUninit for crate::bstr::ByteStr { |
| 601 | /// are implemented in `traits::SelectionContext::copy_clone_conditions()` | 685 | /// are implemented in `traits::SelectionContext::copy_clone_conditions()` |
| 602 | /// in `rustc_trait_selection`. | 686 | /// in `rustc_trait_selection`. |
| 603 | mod impls { | 687 | mod impls { |
| 604 | use super::TrivialClone; | 688 | use super::{Share, TrivialClone}; |
| 605 | use crate::marker::PointeeSized; | 689 | use crate::marker::PointeeSized; |
| 606 | 690 | ||
| 607 | macro_rules! impl_clone { | 691 | macro_rules! impl_clone { |
| ... | @@ -689,6 +773,9 @@ mod impls { | ... | @@ -689,6 +773,9 @@ mod impls { |
| 689 | #[rustc_const_unstable(feature = "const_clone", issue = "142757")] | 773 | #[rustc_const_unstable(feature = "const_clone", issue = "142757")] |
| 690 | unsafe impl<T: PointeeSized> const TrivialClone for &T {} | 774 | unsafe impl<T: PointeeSized> const TrivialClone for &T {} |
| 691 | 775 | ||
| 776 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 777 | impl<T: PointeeSized> Share for &T {} | ||
| 778 | |||
| 692 | /// Shared references can be cloned, but mutable references *cannot*! | 779 | /// Shared references can be cloned, but mutable references *cannot*! |
| 693 | #[stable(feature = "rust1", since = "1.0.0")] | 780 | #[stable(feature = "rust1", since = "1.0.0")] |
| 694 | impl<T: PointeeSized> !Clone for &mut T {} | 781 | impl<T: PointeeSized> !Clone for &mut T {} |
library/core/src/num/f128.rs+1| ... | @@ -33,6 +33,7 @@ pub mod consts { | ... | @@ -33,6 +33,7 @@ pub mod consts { |
| 33 | pub const TAU: f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128; | 33 | pub const TAU: f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128; |
| 34 | 34 | ||
| 35 | /// The golden ratio (φ) | 35 | /// The golden ratio (φ) |
| 36 | #[doc(alias = "phi")] | ||
| 36 | #[unstable(feature = "f128", issue = "116909")] | 37 | #[unstable(feature = "f128", issue = "116909")] |
| 37 | pub const GOLDEN_RATIO: f128 = | 38 | pub const GOLDEN_RATIO: f128 = |
| 38 | 1.61803398874989484820458683436563811772030917980576286213545_f128; | 39 | 1.61803398874989484820458683436563811772030917980576286213545_f128; |
library/core/src/num/f16.rs+1| ... | @@ -35,6 +35,7 @@ pub mod consts { | ... | @@ -35,6 +35,7 @@ pub mod consts { |
| 35 | pub const TAU: f16 = 6.28318530717958647692528676655900577_f16; | 35 | pub const TAU: f16 = 6.28318530717958647692528676655900577_f16; |
| 36 | 36 | ||
| 37 | /// The golden ratio (φ) | 37 | /// The golden ratio (φ) |
| 38 | #[doc(alias = "phi")] | ||
| 38 | #[unstable(feature = "f16", issue = "116909")] | 39 | #[unstable(feature = "f16", issue = "116909")] |
| 39 | pub const GOLDEN_RATIO: f16 = 1.618033988749894848204586834365638118_f16; | 40 | pub const GOLDEN_RATIO: f16 = 1.618033988749894848204586834365638118_f16; |
| 40 | 41 |
library/core/src/num/f32.rs+1| ... | @@ -292,6 +292,7 @@ pub mod consts { | ... | @@ -292,6 +292,7 @@ pub mod consts { |
| 292 | pub const TAU: f32 = 6.28318530717958647692528676655900577_f32; | 292 | pub const TAU: f32 = 6.28318530717958647692528676655900577_f32; |
| 293 | 293 | ||
| 294 | /// The golden ratio (φ) | 294 | /// The golden ratio (φ) |
| 295 | #[doc(alias = "phi")] | ||
| 295 | #[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")] | 296 | #[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")] |
| 296 | pub const GOLDEN_RATIO: f32 = 1.618033988749894848204586834365638118_f32; | 297 | pub const GOLDEN_RATIO: f32 = 1.618033988749894848204586834365638118_f32; |
| 297 | 298 |
library/core/src/num/f64.rs+1| ... | @@ -292,6 +292,7 @@ pub mod consts { | ... | @@ -292,6 +292,7 @@ pub mod consts { |
| 292 | pub const TAU: f64 = 6.28318530717958647692528676655900577_f64; | 292 | pub const TAU: f64 = 6.28318530717958647692528676655900577_f64; |
| 293 | 293 | ||
| 294 | /// The golden ratio (φ) | 294 | /// The golden ratio (φ) |
| 295 | #[doc(alias = "phi")] | ||
| 295 | #[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")] | 296 | #[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")] |
| 296 | pub const GOLDEN_RATIO: f64 = 1.618033988749894848204586834365638118_f64; | 297 | pub const GOLDEN_RATIO: f64 = 1.618033988749894848204586834365638118_f64; |
| 297 | 298 |
library/std/src/lib.rs+1| ... | @@ -369,6 +369,7 @@ | ... | @@ -369,6 +369,7 @@ |
| 369 | #![feature(random)] | 369 | #![feature(random)] |
| 370 | #![feature(raw_os_error_ty)] | 370 | #![feature(raw_os_error_ty)] |
| 371 | #![feature(seek_io_take_position)] | 371 | #![feature(seek_io_take_position)] |
| 372 | #![feature(share_trait)] | ||
| 372 | #![feature(slice_internals)] | 373 | #![feature(slice_internals)] |
| 373 | #![feature(slice_ptr_get)] | 374 | #![feature(slice_ptr_get)] |
| 374 | #![feature(slice_range)] | 375 | #![feature(slice_range)] |
library/std/src/sync/mpsc.rs+8| ... | @@ -142,6 +142,8 @@ | ... | @@ -142,6 +142,8 @@ |
| 142 | // not exposed publicly, but if you are curious about the implementation, | 142 | // not exposed publicly, but if you are curious about the implementation, |
| 143 | // that's where everything is. | 143 | // that's where everything is. |
| 144 | 144 | ||
| 145 | use core::clone::Share; | ||
| 146 | |||
| 145 | use crate::sync::mpmc; | 147 | use crate::sync::mpmc; |
| 146 | use crate::time::{Duration, Instant}; | 148 | use crate::time::{Duration, Instant}; |
| 147 | use crate::{error, fmt}; | 149 | use crate::{error, fmt}; |
| ... | @@ -645,6 +647,9 @@ impl<T> Clone for Sender<T> { | ... | @@ -645,6 +647,9 @@ impl<T> Clone for Sender<T> { |
| 645 | } | 647 | } |
| 646 | } | 648 | } |
| 647 | 649 | ||
| 650 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 651 | impl<T> Share for Sender<T> {} | ||
| 652 | |||
| 648 | #[stable(feature = "mpsc_debug", since = "1.8.0")] | 653 | #[stable(feature = "mpsc_debug", since = "1.8.0")] |
| 649 | impl<T> fmt::Debug for Sender<T> { | 654 | impl<T> fmt::Debug for Sender<T> { |
| 650 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 655 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| ... | @@ -774,6 +779,9 @@ impl<T> Clone for SyncSender<T> { | ... | @@ -774,6 +779,9 @@ impl<T> Clone for SyncSender<T> { |
| 774 | } | 779 | } |
| 775 | } | 780 | } |
| 776 | 781 | ||
| 782 | #[unstable(feature = "share_trait", issue = "156756")] | ||
| 783 | impl<T> Share for SyncSender<T> {} | ||
| 784 | |||
| 777 | #[stable(feature = "mpsc_debug", since = "1.8.0")] | 785 | #[stable(feature = "mpsc_debug", since = "1.8.0")] |
| 778 | impl<T> fmt::Debug for SyncSender<T> { | 786 | impl<T> fmt::Debug for SyncSender<T> { |
| 779 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | 787 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
tests/debuginfo/path.rs-4| ... | @@ -8,12 +8,8 @@ | ... | @@ -8,12 +8,8 @@ |
| 8 | 8 | ||
| 9 | //@ lldb-command:print pathbuf | 9 | //@ lldb-command:print pathbuf |
| 10 | //@ lldb-check:[...] "/some/path" { inner = "/some/path" { inner = { inner = size=10 { [0] = '/' [1] = 's' [2] = 'o' [3] = 'm' [4] = 'e' [5] = '/' [6] = 'p' [7] = 'a' [8] = 't' [9] = 'h' } } } } | 10 | //@ lldb-check:[...] "/some/path" { inner = "/some/path" { inner = { inner = size=10 { [0] = '/' [1] = 's' [2] = 'o' [3] = 'm' [4] = 'e' [5] = '/' [6] = 'p' [7] = 'a' [8] = 't' [9] = 'h' } } } } |
| 11 | //@ lldb-command:po pathbuf | ||
| 12 | //@ lldb-check:"/some/path" | ||
| 13 | //@ lldb-command:print path | 11 | //@ lldb-command:print path |
| 14 | //@ lldb-check:[...] "/some/path" { data_ptr = [...] length = 10 } | 12 | //@ lldb-check:[...] "/some/path" { data_ptr = [...] length = 10 } |
| 15 | //@ lldb-command:po path | ||
| 16 | //@ lldb-check:"/some/path" | ||
| 17 | 13 | ||
| 18 | use std::path::Path; | 14 | use std::path::Path; |
| 19 | 15 |
tests/ui/README.md+4| ... | @@ -1244,6 +1244,10 @@ In this directory, multiple crates are compiled, but some of them have `inline` | ... | @@ -1244,6 +1244,10 @@ In this directory, multiple crates are compiled, but some of them have `inline` |
| 1244 | 1244 | ||
| 1245 | Tests on name shadowing. | 1245 | Tests on name shadowing. |
| 1246 | 1246 | ||
| 1247 | ## `tests/ui/share-trait` | ||
| 1248 | |||
| 1249 | Tests for the unstable `Share` trait. | ||
| 1250 | |||
| 1247 | ## `tests/ui/shell-argfiles/`: `-Z shell-argfiles` command line flag | 1251 | ## `tests/ui/shell-argfiles/`: `-Z shell-argfiles` command line flag |
| 1248 | 1252 | ||
| 1249 | The `-Zshell-argfiles` compiler flag allows argfiles to be parsed using POSIX "shell-style" quoting. When enabled, the compiler will use shlex to parse the arguments from argfiles specified with `@shell:<path>`. | 1253 | The `-Zshell-argfiles` compiler flag allows argfiles to be parsed using POSIX "shell-style" quoting. When enabled, the compiler will use shlex to parse the arguments from argfiles specified with `@shell:<path>`. |
tests/ui/float/f32-into-f32.next-solver.fixed+3| ... | @@ -15,6 +15,9 @@ fn main() { | ... | @@ -15,6 +15,9 @@ fn main() { |
| 15 | foo(1e5_f32); | 15 | foo(1e5_f32); |
| 16 | //~^ WARN falling back to `f32` | 16 | //~^ WARN falling back to `f32` |
| 17 | //~| WARN this was previously accepted | 17 | //~| WARN this was previously accepted |
| 18 | foo(0_f32); | ||
| 19 | //~^ WARN falling back to `f32` | ||
| 20 | //~| WARN this was previously accepted | ||
| 18 | foo(4f32); // no warning | 21 | foo(4f32); // no warning |
| 19 | let x = -4.0_f32; | 22 | let x = -4.0_f32; |
| 20 | //~^ WARN falling back to `f32` | 23 | //~^ WARN falling back to `f32` |
tests/ui/float/f32-into-f32.next-solver.stderr+11-2| ... | @@ -27,7 +27,16 @@ LL | foo(1e5); | ... | @@ -27,7 +27,16 @@ LL | foo(1e5); |
| 27 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | 27 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> |
| 28 | 28 | ||
| 29 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied | 29 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied |
| 30 | --> $DIR/f32-into-f32.rs:19:14 | 30 | --> $DIR/f32-into-f32.rs:18:9 |
| 31 | | | ||
| 32 | LL | foo(0.); | ||
| 33 | | ^^ help: explicitly specify the type as `f32`: `0_f32` | ||
| 34 | | | ||
| 35 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| 36 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | ||
| 37 | |||
| 38 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied | ||
| 39 | --> $DIR/f32-into-f32.rs:22:14 | ||
| 31 | | | 40 | | |
| 32 | LL | let x = -4.0; | 41 | LL | let x = -4.0; |
| 33 | | ^^^ help: explicitly specify the type as `f32`: `4.0_f32` | 42 | | ^^^ help: explicitly specify the type as `f32`: `4.0_f32` |
| ... | @@ -35,5 +44,5 @@ LL | let x = -4.0; | ... | @@ -35,5 +44,5 @@ LL | let x = -4.0; |
| 35 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | 44 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! |
| 36 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | 45 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> |
| 37 | 46 | ||
| 38 | warning: 4 warnings emitted | 47 | warning: 5 warnings emitted |
| 39 | 48 |
tests/ui/float/f32-into-f32.old-solver.fixed+3| ... | @@ -15,6 +15,9 @@ fn main() { | ... | @@ -15,6 +15,9 @@ fn main() { |
| 15 | foo(1e5_f32); | 15 | foo(1e5_f32); |
| 16 | //~^ WARN falling back to `f32` | 16 | //~^ WARN falling back to `f32` |
| 17 | //~| WARN this was previously accepted | 17 | //~| WARN this was previously accepted |
| 18 | foo(0_f32); | ||
| 19 | //~^ WARN falling back to `f32` | ||
| 20 | //~| WARN this was previously accepted | ||
| 18 | foo(4f32); // no warning | 21 | foo(4f32); // no warning |
| 19 | let x = -4.0_f32; | 22 | let x = -4.0_f32; |
| 20 | //~^ WARN falling back to `f32` | 23 | //~^ WARN falling back to `f32` |
tests/ui/float/f32-into-f32.old-solver.stderr+11-2| ... | @@ -27,7 +27,16 @@ LL | foo(1e5); | ... | @@ -27,7 +27,16 @@ LL | foo(1e5); |
| 27 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | 27 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> |
| 28 | 28 | ||
| 29 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied | 29 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied |
| 30 | --> $DIR/f32-into-f32.rs:19:14 | 30 | --> $DIR/f32-into-f32.rs:18:9 |
| 31 | | | ||
| 32 | LL | foo(0.); | ||
| 33 | | ^^ help: explicitly specify the type as `f32`: `0_f32` | ||
| 34 | | | ||
| 35 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
| 36 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | ||
| 37 | |||
| 38 | warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied | ||
| 39 | --> $DIR/f32-into-f32.rs:22:14 | ||
| 31 | | | 40 | | |
| 32 | LL | let x = -4.0; | 41 | LL | let x = -4.0; |
| 33 | | ^^^ help: explicitly specify the type as `f32`: `4.0_f32` | 42 | | ^^^ help: explicitly specify the type as `f32`: `4.0_f32` |
| ... | @@ -35,5 +44,5 @@ LL | let x = -4.0; | ... | @@ -35,5 +44,5 @@ LL | let x = -4.0; |
| 35 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | 44 | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! |
| 36 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> | 45 | = note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024> |
| 37 | 46 | ||
| 38 | warning: 4 warnings emitted | 47 | warning: 5 warnings emitted |
| 39 | 48 |
tests/ui/float/f32-into-f32.rs+3| ... | @@ -15,6 +15,9 @@ fn main() { | ... | @@ -15,6 +15,9 @@ fn main() { |
| 15 | foo(1e5); | 15 | foo(1e5); |
| 16 | //~^ WARN falling back to `f32` | 16 | //~^ WARN falling back to `f32` |
| 17 | //~| WARN this was previously accepted | 17 | //~| WARN this was previously accepted |
| 18 | foo(0.); | ||
| 19 | //~^ WARN falling back to `f32` | ||
| 20 | //~| WARN this was previously accepted | ||
| 18 | foo(4f32); // no warning | 21 | foo(4f32); // no warning |
| 19 | let x = -4.0; | 22 | let x = -4.0; |
| 20 | //~^ WARN falling back to `f32` | 23 | //~^ WARN falling back to `f32` |
tests/ui/reborrow/reborrow_multi_field_validation.rs created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #![feature(reborrow)] | ||
| 2 | |||
| 3 | use std::marker::Reborrow; | ||
| 4 | |||
| 5 | // Regression test: `reborrow_info` must validate ALL data fields, | ||
| 6 | // not just stop at the first Reborrow field. | ||
| 7 | |||
| 8 | struct Bad<'a> { | ||
| 9 | first: &'a mut i32, | ||
| 10 | second: String, //~ ERROR the trait bound `String: Copy` is not satisfied | ||
| 11 | } | ||
| 12 | |||
| 13 | impl<'a> Reborrow for Bad<'a> {} | ||
| 14 | |||
| 15 | fn main() {} | ||
tests/ui/reborrow/reborrow_multi_field_validation.stderr created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | error[E0277]: the trait bound `String: Copy` is not satisfied | ||
| 2 | --> $DIR/reborrow_multi_field_validation.rs:10:5 | ||
| 3 | | | ||
| 4 | LL | second: String, | ||
| 5 | | ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String` | ||
| 6 | |||
| 7 | error: aborting due to 1 previous error | ||
| 8 | |||
| 9 | For more information about this error, try `rustc --explain E0277`. | ||
tests/ui/share-trait/share-trait-arc.rs created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | //@ run-pass | ||
| 2 | |||
| 3 | #![feature(share_trait)] | ||
| 4 | |||
| 5 | use std::clone::Share; | ||
| 6 | use std::sync::{Arc, Mutex}; | ||
| 7 | |||
| 8 | trait Value { | ||
| 9 | fn get(&self) -> i32; | ||
| 10 | } | ||
| 11 | |||
| 12 | impl Value for Mutex<i32> { | ||
| 13 | fn get(&self) -> i32 { | ||
| 14 | *self.lock().unwrap() | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | fn main() { | ||
| 19 | let value = Arc::new(Mutex::new(1)); | ||
| 20 | let shared = value.share(); | ||
| 21 | |||
| 22 | assert!(Arc::ptr_eq(&value, &shared)); | ||
| 23 | *shared.lock().unwrap() = 2; | ||
| 24 | assert_eq!(*value.lock().unwrap(), 2); | ||
| 25 | |||
| 26 | let dyn_value: Arc<dyn Value + Send + Sync> = Arc::new(Mutex::new(3)); | ||
| 27 | let shared_dyn_value = dyn_value.share(); | ||
| 28 | |||
| 29 | assert!(Arc::ptr_eq(&dyn_value, &shared_dyn_value)); | ||
| 30 | assert_eq!(shared_dyn_value.get(), 3); | ||
| 31 | } | ||
tests/ui/share-trait/share-trait-mpsc-sender.rs created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | //@ run-pass | ||
| 2 | |||
| 3 | #![feature(share_trait)] | ||
| 4 | |||
| 5 | use std::clone::Share; | ||
| 6 | use std::sync::mpsc::channel; | ||
| 7 | |||
| 8 | fn main() { | ||
| 9 | let (sender, receiver) = channel(); | ||
| 10 | let shared_sender = sender.share(); | ||
| 11 | |||
| 12 | sender.send(1).unwrap(); | ||
| 13 | shared_sender.send(2).unwrap(); | ||
| 14 | |||
| 15 | let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()]; | ||
| 16 | received.sort(); | ||
| 17 | |||
| 18 | assert_eq!(received, [1, 2]); | ||
| 19 | } | ||
tests/ui/share-trait/share-trait-mpsc-sync-sender.rs created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | //@ run-pass | ||
| 2 | |||
| 3 | #![feature(share_trait)] | ||
| 4 | |||
| 5 | use std::clone::Share; | ||
| 6 | use std::sync::mpsc::sync_channel; | ||
| 7 | |||
| 8 | fn main() { | ||
| 9 | let (sender, receiver) = sync_channel(2); | ||
| 10 | let shared_sender = sender.share(); | ||
| 11 | |||
| 12 | sender.send(1).unwrap(); | ||
| 13 | shared_sender.send(2).unwrap(); | ||
| 14 | |||
| 15 | let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()]; | ||
| 16 | received.sort(); | ||
| 17 | |||
| 18 | assert_eq!(received, [1, 2]); | ||
| 19 | } | ||
tests/ui/share-trait/share-trait-no-feature.rs created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | use std::clone::Share; | ||
| 2 | //~^ ERROR use of unstable library feature `share_trait` | ||
| 3 | |||
| 4 | #[derive(Clone)] | ||
| 5 | struct Alias; | ||
| 6 | |||
| 7 | impl Share for Alias {} | ||
| 8 | //~^ ERROR use of unstable library feature `share_trait` | ||
| 9 | |||
| 10 | fn share_generic<T: Share>(value: &T) -> T { | ||
| 11 | //~^ ERROR use of unstable library feature `share_trait` | ||
| 12 | value.share() | ||
| 13 | //~^ ERROR use of unstable library feature `share_trait` | ||
| 14 | } | ||
| 15 | |||
| 16 | fn main() { | ||
| 17 | let value = Alias; | ||
| 18 | let _ = Share::share(&value); | ||
| 19 | //~^ ERROR use of unstable library feature `share_trait` | ||
| 20 | } | ||
tests/ui/share-trait/share-trait-no-feature.stderr created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | error[E0658]: use of unstable library feature `share_trait` | ||
| 2 | --> $DIR/share-trait-no-feature.rs:1:5 | ||
| 3 | | | ||
| 4 | LL | use std::clone::Share; | ||
| 5 | | ^^^^^^^^^^^^^^^^^ | ||
| 6 | | | ||
| 7 | = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| 8 | = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| 9 | = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| 10 | |||
| 11 | error[E0658]: use of unstable library feature `share_trait` | ||
| 12 | --> $DIR/share-trait-no-feature.rs:7:6 | ||
| 13 | | | ||
| 14 | LL | impl Share for Alias {} | ||
| 15 | | ^^^^^ | ||
| 16 | | | ||
| 17 | = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| 18 | = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| 19 | = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| 20 | |||
| 21 | error[E0658]: use of unstable library feature `share_trait` | ||
| 22 | --> $DIR/share-trait-no-feature.rs:10:21 | ||
| 23 | | | ||
| 24 | LL | fn share_generic<T: Share>(value: &T) -> T { | ||
| 25 | | ^^^^^ | ||
| 26 | | | ||
| 27 | = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| 28 | = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| 29 | = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| 30 | |||
| 31 | error[E0658]: use of unstable library feature `share_trait` | ||
| 32 | --> $DIR/share-trait-no-feature.rs:18:13 | ||
| 33 | | | ||
| 34 | LL | let _ = Share::share(&value); | ||
| 35 | | ^^^^^^^^^^^^ | ||
| 36 | | | ||
| 37 | = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| 38 | = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| 39 | = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| 40 | |||
| 41 | error[E0658]: use of unstable library feature `share_trait` | ||
| 42 | --> $DIR/share-trait-no-feature.rs:12:11 | ||
| 43 | | | ||
| 44 | LL | value.share() | ||
| 45 | | ^^^^^ | ||
| 46 | | | ||
| 47 | = note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information | ||
| 48 | = help: add `#![feature(share_trait)]` to the crate attributes to enable | ||
| 49 | = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date | ||
| 50 | |||
| 51 | error: aborting due to 5 previous errors | ||
| 52 | |||
| 53 | For more information about this error, try `rustc --explain E0658`. | ||
tests/ui/share-trait/share-trait-non-implementors.rs created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #![feature(share_trait)] | ||
| 2 | |||
| 3 | use std::clone::Share; | ||
| 4 | |||
| 5 | fn require_share<T: Share>() {} | ||
| 6 | |||
| 7 | fn main() { | ||
| 8 | require_share::<&mut i32>(); | ||
| 9 | //~^ ERROR the trait bound `&mut i32: Share` is not satisfied | ||
| 10 | |||
| 11 | require_share::<String>(); | ||
| 12 | //~^ ERROR the trait bound `String: Share` is not satisfied | ||
| 13 | |||
| 14 | require_share::<Vec<i32>>(); | ||
| 15 | //~^ ERROR the trait bound `Vec<i32>: Share` is not satisfied | ||
| 16 | |||
| 17 | require_share::<Box<i32>>(); | ||
| 18 | //~^ ERROR the trait bound `Box<i32>: Share` is not satisfied | ||
| 19 | } | ||
tests/ui/share-trait/share-trait-non-implementors.stderr created+76| ... | @@ -0,0 +1,76 @@ | ||
| 1 | error[E0277]: the trait bound `&mut i32: Share` is not satisfied | ||
| 2 | --> $DIR/share-trait-non-implementors.rs:8:21 | ||
| 3 | | | ||
| 4 | LL | require_share::<&mut i32>(); | ||
| 5 | | ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `&mut i32` | ||
| 6 | | | ||
| 7 | = help: the following other types implement trait `Share`: | ||
| 8 | &T | ||
| 9 | Arc<T, A> | ||
| 10 | Rc<T, A> | ||
| 11 | SyncSender<T> | ||
| 12 | std::sync::mpsc::Sender<T> | ||
| 13 | = note: `Share` is implemented for `&i32`, but not for `&mut i32` | ||
| 14 | note: required by a bound in `require_share` | ||
| 15 | --> $DIR/share-trait-non-implementors.rs:5:21 | ||
| 16 | | | ||
| 17 | LL | fn require_share<T: Share>() {} | ||
| 18 | | ^^^^^ required by this bound in `require_share` | ||
| 19 | |||
| 20 | error[E0277]: the trait bound `String: Share` is not satisfied | ||
| 21 | --> $DIR/share-trait-non-implementors.rs:11:21 | ||
| 22 | | | ||
| 23 | LL | require_share::<String>(); | ||
| 24 | | ^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `String` | ||
| 25 | | | ||
| 26 | = help: the following other types implement trait `Share`: | ||
| 27 | &T | ||
| 28 | Arc<T, A> | ||
| 29 | Rc<T, A> | ||
| 30 | SyncSender<T> | ||
| 31 | std::sync::mpsc::Sender<T> | ||
| 32 | note: required by a bound in `require_share` | ||
| 33 | --> $DIR/share-trait-non-implementors.rs:5:21 | ||
| 34 | | | ||
| 35 | LL | fn require_share<T: Share>() {} | ||
| 36 | | ^^^^^ required by this bound in `require_share` | ||
| 37 | |||
| 38 | error[E0277]: the trait bound `Vec<i32>: Share` is not satisfied | ||
| 39 | --> $DIR/share-trait-non-implementors.rs:14:21 | ||
| 40 | | | ||
| 41 | LL | require_share::<Vec<i32>>(); | ||
| 42 | | ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `Vec<i32>` | ||
| 43 | | | ||
| 44 | = help: the following other types implement trait `Share`: | ||
| 45 | &T | ||
| 46 | Arc<T, A> | ||
| 47 | Rc<T, A> | ||
| 48 | SyncSender<T> | ||
| 49 | std::sync::mpsc::Sender<T> | ||
| 50 | note: required by a bound in `require_share` | ||
| 51 | --> $DIR/share-trait-non-implementors.rs:5:21 | ||
| 52 | | | ||
| 53 | LL | fn require_share<T: Share>() {} | ||
| 54 | | ^^^^^ required by this bound in `require_share` | ||
| 55 | |||
| 56 | error[E0277]: the trait bound `Box<i32>: Share` is not satisfied | ||
| 57 | --> $DIR/share-trait-non-implementors.rs:17:21 | ||
| 58 | | | ||
| 59 | LL | require_share::<Box<i32>>(); | ||
| 60 | | ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `Box<i32>` | ||
| 61 | | | ||
| 62 | = help: the following other types implement trait `Share`: | ||
| 63 | &T | ||
| 64 | Arc<T, A> | ||
| 65 | Rc<T, A> | ||
| 66 | SyncSender<T> | ||
| 67 | std::sync::mpsc::Sender<T> | ||
| 68 | note: required by a bound in `require_share` | ||
| 69 | --> $DIR/share-trait-non-implementors.rs:5:21 | ||
| 70 | | | ||
| 71 | LL | fn require_share<T: Share>() {} | ||
| 72 | | ^^^^^ required by this bound in `require_share` | ||
| 73 | |||
| 74 | error: aborting due to 4 previous errors | ||
| 75 | |||
| 76 | For more information about this error, try `rustc --explain E0277`. | ||
tests/ui/share-trait/share-trait-not-in-prelude.rs created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #![feature(share_trait)] | ||
| 2 | |||
| 3 | #[derive(Clone)] | ||
| 4 | struct Alias; | ||
| 5 | |||
| 6 | impl Share for Alias {} | ||
| 7 | //~^ ERROR cannot find trait `Share` in this scope | ||
| 8 | |||
| 9 | fn main() {} | ||
tests/ui/share-trait/share-trait-not-in-prelude.stderr created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | error[E0405]: cannot find trait `Share` in this scope | ||
| 2 | --> $DIR/share-trait-not-in-prelude.rs:6:6 | ||
| 3 | | | ||
| 4 | LL | impl Share for Alias {} | ||
| 5 | | ^^^^^ not found in this scope | ||
| 6 | | | ||
| 7 | help: consider importing this trait | ||
| 8 | | | ||
| 9 | LL + use std::clone::Share; | ||
| 10 | | | ||
| 11 | |||
| 12 | error: aborting due to 1 previous error | ||
| 13 | |||
| 14 | For more information about this error, try `rustc --explain E0405`. | ||
tests/ui/share-trait/share-trait-rc.rs created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | //@ run-pass | ||
| 2 | |||
| 3 | #![feature(share_trait)] | ||
| 4 | |||
| 5 | use std::cell::Cell; | ||
| 6 | use std::clone::Share; | ||
| 7 | use std::rc::Rc; | ||
| 8 | |||
| 9 | trait Value { | ||
| 10 | fn get(&self) -> i32; | ||
| 11 | } | ||
| 12 | |||
| 13 | impl Value for Cell<i32> { | ||
| 14 | fn get(&self) -> i32 { | ||
| 15 | Cell::get(self) | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | fn main() { | ||
| 20 | let value = Rc::new(Cell::new(1)); | ||
| 21 | let shared = value.share(); | ||
| 22 | |||
| 23 | assert!(Rc::ptr_eq(&value, &shared)); | ||
| 24 | shared.set(2); | ||
| 25 | assert_eq!(value.get(), 2); | ||
| 26 | |||
| 27 | let dyn_value: Rc<dyn Value> = Rc::new(Cell::new(3)); | ||
| 28 | let shared_dyn_value = dyn_value.share(); | ||
| 29 | |||
| 30 | assert!(Rc::ptr_eq(&dyn_value, &shared_dyn_value)); | ||
| 31 | assert_eq!(shared_dyn_value.get(), 3); | ||
| 32 | } | ||
tests/ui/share-trait/share-trait-requires-clone.rs created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #![feature(share_trait)] | ||
| 2 | |||
| 3 | use std::clone::Share; | ||
| 4 | |||
| 5 | struct NotClone; | ||
| 6 | |||
| 7 | impl Share for NotClone {} | ||
| 8 | //~^ ERROR the trait bound `NotClone: Clone` is not satisfied | ||
| 9 | |||
| 10 | fn main() {} | ||
tests/ui/share-trait/share-trait-requires-clone.stderr created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | error[E0277]: the trait bound `NotClone: Clone` is not satisfied | ||
| 2 | --> $DIR/share-trait-requires-clone.rs:7:16 | ||
| 3 | | | ||
| 4 | LL | impl Share for NotClone {} | ||
| 5 | | ^^^^^^^^ the trait `Clone` is not implemented for `NotClone` | ||
| 6 | | | ||
| 7 | note: required by a bound in `Share` | ||
| 8 | --> $SRC_DIR/core/src/clone.rs:LL:COL | ||
| 9 | help: consider annotating `NotClone` with `#[derive(Clone)]` | ||
| 10 | | | ||
| 11 | LL + #[derive(Clone)] | ||
| 12 | LL | struct NotClone; | ||
| 13 | | | ||
| 14 | |||
| 15 | error: aborting due to 1 previous error | ||
| 16 | |||
| 17 | For more information about this error, try `rustc --explain E0277`. | ||
tests/ui/share-trait/share-trait.rs created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | //@ check-pass | ||
| 2 | |||
| 3 | #![feature(share_trait)] | ||
| 4 | |||
| 5 | extern crate core; | ||
| 6 | |||
| 7 | use core::clone::Share; | ||
| 8 | |||
| 9 | #[derive(Debug, PartialEq)] | ||
| 10 | struct Alias(u8); | ||
| 11 | |||
| 12 | impl Clone for Alias { | ||
| 13 | fn clone(&self) -> Self { | ||
| 14 | Alias(self.0 + 1) | ||
| 15 | } | ||
| 16 | } | ||
| 17 | |||
| 18 | impl Share for Alias {} | ||
| 19 | |||
| 20 | fn share_generic<T: Share>(value: &T) -> T { | ||
| 21 | value.share() | ||
| 22 | } | ||
| 23 | |||
| 24 | fn main() { | ||
| 25 | let value = Alias(1); | ||
| 26 | |||
| 27 | assert_eq!(Share::share(&value), Alias(2)); | ||
| 28 | assert_eq!(std::clone::Share::share(&value), Alias(2)); | ||
| 29 | assert_eq!(value.share(), Alias(2)); | ||
| 30 | assert_eq!(share_generic(&value), Alias(2)); | ||
| 31 | |||
| 32 | let number = 3; | ||
| 33 | let shared = &number; | ||
| 34 | let shared_again = shared.share(); | ||
| 35 | let shared_fqs: &i32 = Share::share(&shared); | ||
| 36 | let shared_generic: &i32 = share_generic(&shared); | ||
| 37 | |||
| 38 | assert!(std::ptr::eq(shared, shared_again)); | ||
| 39 | assert!(std::ptr::eq(shared_fqs, shared)); | ||
| 40 | assert!(std::ptr::eq(shared_generic, shared)); | ||
| 41 | |||
| 42 | let slice: &[i32] = &[1, 2, 3]; | ||
| 43 | assert!(std::ptr::eq(slice, slice.share())); | ||
| 44 | } | ||