Auto merge of #156870 - JonathanBrouwer:rollup-PbM4nVA, r=JonathanBrouwer

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)
This commit is contained in:
bors
2026-05-24 06:29:32 +00:00
35 changed files with 542 additions and 14 deletions
+1
View File
@@ -569,6 +569,7 @@ Philipp Matthias Schäfer <philipp.matthias.schaefer@posteo.de>
phosphorus <steepout@qq.com>
Pierre Krieger <pierre.krieger1708@gmail.com>
pierwill <pierwill@users.noreply.github.com> <19642016+pierwill@users.noreply.github.com>
Pieter-Louis Schoeman <pl.schoeman44@gmail.com> <127837395+P8L1@users.noreply.github.com>
Pietro Albini <pietro@pietroalbini.org> <pietro@pietroalbini.io>
Pietro Albini <pietro@pietroalbini.org> <pietro.albini@ferrous-systems.com>
Pradyumna Rahul <prkinformed@gmail.com>
@@ -563,8 +563,8 @@ pub(crate) fn reborrow_info<'tcx>(
)
.is_ok()
{
// Field implements Reborrow.
return Ok(());
// Field implements Reborrow, check remaining fields.
continue;
}
// Field does not implement Reborrow: it must be Copy.
+7 -1
View File
@@ -171,7 +171,13 @@ fn calculate_fallback_to_f32(&self, unresolved_variables: &[Ty<'tcx>]) -> UnordS
.inspect(|vid| {
let origin = self.float_var_origin(*vid);
// Show the entire literal in the suggestion to make it clearer.
let literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok();
let mut literal = self.tcx.sess.source_map().span_to_snippet(origin.span).ok();
// A `.` at the end of the literal is no longer necessary if `f32` is explicitly specified
if let Some(ref mut literal) = literal
&& literal.ends_with('.')
{
literal.pop();
}
self.tcx.emit_node_span_lint(
FLOAT_LITERAL_F32_FALLBACK,
origin.lint_id.unwrap_or(CRATE_HIR_ID),
+1
View File
@@ -144,6 +144,7 @@
#![feature(ptr_metadata)]
#![feature(rev_into_inner)]
#![feature(set_ptr_value)]
#![feature(share_trait)]
#![feature(sized_type_properties)]
#![feature(slice_from_ptr_range)]
#![feature(slice_index_methods)]
+4 -1
View File
@@ -245,7 +245,7 @@
use core::cell::{Cell, CloneFromCell};
#[cfg(not(no_global_oom_handling))]
use core::clone::TrivialClone;
use core::clone::{CloneToUninit, UseCloned};
use core::clone::{CloneToUninit, Share, UseCloned};
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::intrinsics::abort;
@@ -2525,6 +2525,9 @@ fn clone(&self) -> Self {
#[unstable(feature = "ergonomic_clones", issue = "132290")]
impl<T: ?Sized, A: Allocator + Clone> UseCloned for Rc<T, A> {}
#[unstable(feature = "share_trait", issue = "156756")]
impl<T: ?Sized, A: Allocator + Clone> Share for Rc<T, A> {}
#[cfg(not(no_global_oom_handling))]
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: Default> Default for Rc<T> {
+4 -1
View File
@@ -12,7 +12,7 @@
use core::cell::CloneFromCell;
#[cfg(not(no_global_oom_handling))]
use core::clone::TrivialClone;
use core::clone::{CloneToUninit, UseCloned};
use core::clone::{CloneToUninit, Share, UseCloned};
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};
use core::intrinsics::abort;
@@ -2436,6 +2436,9 @@ fn clone(&self) -> Arc<T, A> {
#[unstable(feature = "ergonomic_clones", issue = "132290")]
impl<T: ?Sized, A: Allocator + Clone> UseCloned for Arc<T, A> {}
#[unstable(feature = "share_trait", issue = "156756")]
impl<T: ?Sized, A: Allocator + Clone> Share for Arc<T, A> {}
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: ?Sized, A: Allocator> Deref for Arc<T, A> {
type Target = T;
+88 -1
View File
@@ -290,6 +290,90 @@ fn clone_from(&mut self, source: &Self)
/* compiler built-in */
}
/// A trait for types whose [`Clone`] operation creates another alias to the same
/// logical resource or shared state.
///
/// `Share` marks types where cloning creates another handle, reference, or alias
/// to the same logical resource or shared state, rather than an independent owned
/// value. The distinction is semantic, not cost-based: implementing `Share` does
/// not merely mean that cloning is cheap, constant-time, allocation-free, or
/// convenient.
///
/// Calling [`share`](Share::share) is equivalent to calling [`clone`](Clone::clone)
/// for implementors, but communicates that the resulting value aliases the same
/// underlying resource.
///
/// Shared references, `Rc<T>`, `Arc<T>`, `Sender<T>`, and `SyncSender<T>` are
/// examples of types that can be shared this way. Types such as `Vec<T>`,
/// `String`, and `Box<T>` are not `Share` even though they implement `Clone`,
/// because cloning them creates another owned value rather than another handle
/// to the same logical resource.
///
/// # Examples
///
/// ```
/// #![feature(share_trait)]
///
/// use std::cell::Cell;
/// use std::clone::Share;
/// use std::rc::Rc;
/// use std::sync::{
/// Arc,
/// atomic::{AtomicUsize, Ordering},
/// };
///
/// let value = 1;
/// let reference = &value;
/// assert!(std::ptr::eq(reference, reference.share()));
///
/// let rc = Rc::new(Cell::new(2));
/// let shared_rc = rc.share();
/// assert!(Rc::ptr_eq(&rc, &shared_rc));
/// shared_rc.set(3);
/// assert_eq!(rc.get(), 3);
///
/// let arc = Arc::new(AtomicUsize::new(4));
/// let shared_arc = arc.share();
/// assert!(Arc::ptr_eq(&arc, &shared_arc));
/// shared_arc.store(5, Ordering::Relaxed);
/// assert_eq!(arc.load(Ordering::Relaxed), 5);
/// ```
///
/// ```
/// #![feature(share_trait)]
///
/// use std::clone::Share;
/// use std::sync::mpsc::{channel, sync_channel};
///
/// let (sender, receiver) = channel();
/// let shared_sender = sender.share();
/// sender.send(1).unwrap();
/// shared_sender.send(2).unwrap();
///
/// let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()];
/// received.sort();
/// assert_eq!(received, [1, 2]);
///
/// let (sync_sender, sync_receiver) = sync_channel(2);
/// let shared_sync_sender = sync_sender.share();
/// sync_sender.send(3).unwrap();
/// shared_sync_sender.send(4).unwrap();
///
/// let mut received = [sync_receiver.recv().unwrap(), sync_receiver.recv().unwrap()];
/// received.sort();
/// assert_eq!(received, [3, 4]);
/// ```
#[unstable(feature = "share_trait", issue = "156756")]
pub trait Share: Clone {
/// Creates another alias to the same underlying resource or shared state.
///
/// This is equivalent to calling [`Clone::clone`].
#[unstable(feature = "share_trait", issue = "156756")]
fn share(&self) -> Self {
Clone::clone(self)
}
}
/// Trait for objects whose [`Clone`] impl is lightweight (e.g. reference-counted)
///
/// Cloning an object implementing this trait should in general:
@@ -601,7 +685,7 @@ unsafe fn clone_to_uninit(&self, dst: *mut u8) {
/// are implemented in `traits::SelectionContext::copy_clone_conditions()`
/// in `rustc_trait_selection`.
mod impls {
use super::TrivialClone;
use super::{Share, TrivialClone};
use crate::marker::PointeeSized;
macro_rules! impl_clone {
@@ -689,6 +773,9 @@ fn clone(&self) -> Self {
#[rustc_const_unstable(feature = "const_clone", issue = "142757")]
unsafe impl<T: PointeeSized> const TrivialClone for &T {}
#[unstable(feature = "share_trait", issue = "156756")]
impl<T: PointeeSized> Share for &T {}
/// Shared references can be cloned, but mutable references *cannot*!
#[stable(feature = "rust1", since = "1.0.0")]
impl<T: PointeeSized> !Clone for &mut T {}
+1
View File
@@ -33,6 +33,7 @@ pub mod consts {
pub const TAU: f128 = 6.28318530717958647692528676655900576839433879875021164194989_f128;
/// The golden ratio (φ)
#[doc(alias = "phi")]
#[unstable(feature = "f128", issue = "116909")]
pub const GOLDEN_RATIO: f128 =
1.61803398874989484820458683436563811772030917980576286213545_f128;
+1
View File
@@ -35,6 +35,7 @@ pub mod consts {
pub const TAU: f16 = 6.28318530717958647692528676655900577_f16;
/// The golden ratio (φ)
#[doc(alias = "phi")]
#[unstable(feature = "f16", issue = "116909")]
pub const GOLDEN_RATIO: f16 = 1.618033988749894848204586834365638118_f16;
+1
View File
@@ -292,6 +292,7 @@ pub mod consts {
pub const TAU: f32 = 6.28318530717958647692528676655900577_f32;
/// The golden ratio (φ)
#[doc(alias = "phi")]
#[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")]
pub const GOLDEN_RATIO: f32 = 1.618033988749894848204586834365638118_f32;
+1
View File
@@ -292,6 +292,7 @@ pub mod consts {
pub const TAU: f64 = 6.28318530717958647692528676655900577_f64;
/// The golden ratio (φ)
#[doc(alias = "phi")]
#[stable(feature = "euler_gamma_golden_ratio", since = "1.94.0")]
pub const GOLDEN_RATIO: f64 = 1.618033988749894848204586834365638118_f64;
+1
View File
@@ -369,6 +369,7 @@
#![feature(random)]
#![feature(raw_os_error_ty)]
#![feature(seek_io_take_position)]
#![feature(share_trait)]
#![feature(slice_internals)]
#![feature(slice_ptr_get)]
#![feature(slice_range)]
+8
View File
@@ -142,6 +142,8 @@
// not exposed publicly, but if you are curious about the implementation,
// that's where everything is.
use core::clone::Share;
use crate::sync::mpmc;
use crate::time::{Duration, Instant};
use crate::{error, fmt};
@@ -645,6 +647,9 @@ fn clone(&self) -> Sender<T> {
}
}
#[unstable(feature = "share_trait", issue = "156756")]
impl<T> Share for Sender<T> {}
#[stable(feature = "mpsc_debug", since = "1.8.0")]
impl<T> fmt::Debug for Sender<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
@@ -774,6 +779,9 @@ fn clone(&self) -> SyncSender<T> {
}
}
#[unstable(feature = "share_trait", issue = "156756")]
impl<T> Share for SyncSender<T> {}
#[stable(feature = "mpsc_debug", since = "1.8.0")]
impl<T> fmt::Debug for SyncSender<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
-4
View File
@@ -8,12 +8,8 @@
//@ lldb-command:print pathbuf
//@ 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' } } } }
//@ lldb-command:po pathbuf
//@ lldb-check:"/some/path"
//@ lldb-command:print path
//@ lldb-check:[...] "/some/path" { data_ptr = [...] length = 10 }
//@ lldb-command:po path
//@ lldb-check:"/some/path"
use std::path::Path;
+4
View File
@@ -1244,6 +1244,10 @@ In this directory, multiple crates are compiled, but some of them have `inline`
Tests on name shadowing.
## `tests/ui/share-trait`
Tests for the unstable `Share` trait.
## `tests/ui/shell-argfiles/`: `-Z shell-argfiles` command line flag
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>`.
@@ -15,6 +15,9 @@ fn main() {
foo(1e5_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0_f32;
//~^ WARN falling back to `f32`
+11 -2
View File
@@ -27,7 +27,16 @@ LL | foo(1e5);
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
--> $DIR/f32-into-f32.rs:18:9
|
LL | foo(0.);
| ^^ help: explicitly specify the type as `f32`: `0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:22:14
|
LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
@@ -35,5 +44,5 @@ LL | let x = -4.0;
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: 4 warnings emitted
warning: 5 warnings emitted
@@ -15,6 +15,9 @@ fn main() {
foo(1e5_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0_f32);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0_f32;
//~^ WARN falling back to `f32`
+11 -2
View File
@@ -27,7 +27,16 @@ LL | foo(1e5);
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:19:14
--> $DIR/f32-into-f32.rs:18:9
|
LL | foo(0.);
| ^^ help: explicitly specify the type as `f32`: `0_f32`
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: falling back to `f32` as the trait bound `f32: From<f64>` is not satisfied
--> $DIR/f32-into-f32.rs:22:14
|
LL | let x = -4.0;
| ^^^ help: explicitly specify the type as `f32`: `4.0_f32`
@@ -35,5 +44,5 @@ LL | let x = -4.0;
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #154024 <https://github.com/rust-lang/rust/issues/154024>
warning: 4 warnings emitted
warning: 5 warnings emitted
+3
View File
@@ -15,6 +15,9 @@ fn main() {
foo(1e5);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(0.);
//~^ WARN falling back to `f32`
//~| WARN this was previously accepted
foo(4f32); // no warning
let x = -4.0;
//~^ WARN falling back to `f32`
@@ -0,0 +1,15 @@
#![feature(reborrow)]
use std::marker::Reborrow;
// Regression test: `reborrow_info` must validate ALL data fields,
// not just stop at the first Reborrow field.
struct Bad<'a> {
first: &'a mut i32,
second: String, //~ ERROR the trait bound `String: Copy` is not satisfied
}
impl<'a> Reborrow for Bad<'a> {}
fn main() {}
@@ -0,0 +1,9 @@
error[E0277]: the trait bound `String: Copy` is not satisfied
--> $DIR/reborrow_multi_field_validation.rs:10:5
|
LL | second: String,
| ^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `String`
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
+31
View File
@@ -0,0 +1,31 @@
//@ run-pass
#![feature(share_trait)]
use std::clone::Share;
use std::sync::{Arc, Mutex};
trait Value {
fn get(&self) -> i32;
}
impl Value for Mutex<i32> {
fn get(&self) -> i32 {
*self.lock().unwrap()
}
}
fn main() {
let value = Arc::new(Mutex::new(1));
let shared = value.share();
assert!(Arc::ptr_eq(&value, &shared));
*shared.lock().unwrap() = 2;
assert_eq!(*value.lock().unwrap(), 2);
let dyn_value: Arc<dyn Value + Send + Sync> = Arc::new(Mutex::new(3));
let shared_dyn_value = dyn_value.share();
assert!(Arc::ptr_eq(&dyn_value, &shared_dyn_value));
assert_eq!(shared_dyn_value.get(), 3);
}
@@ -0,0 +1,19 @@
//@ run-pass
#![feature(share_trait)]
use std::clone::Share;
use std::sync::mpsc::channel;
fn main() {
let (sender, receiver) = channel();
let shared_sender = sender.share();
sender.send(1).unwrap();
shared_sender.send(2).unwrap();
let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()];
received.sort();
assert_eq!(received, [1, 2]);
}
@@ -0,0 +1,19 @@
//@ run-pass
#![feature(share_trait)]
use std::clone::Share;
use std::sync::mpsc::sync_channel;
fn main() {
let (sender, receiver) = sync_channel(2);
let shared_sender = sender.share();
sender.send(1).unwrap();
shared_sender.send(2).unwrap();
let mut received = [receiver.recv().unwrap(), receiver.recv().unwrap()];
received.sort();
assert_eq!(received, [1, 2]);
}
@@ -0,0 +1,20 @@
use std::clone::Share;
//~^ ERROR use of unstable library feature `share_trait`
#[derive(Clone)]
struct Alias;
impl Share for Alias {}
//~^ ERROR use of unstable library feature `share_trait`
fn share_generic<T: Share>(value: &T) -> T {
//~^ ERROR use of unstable library feature `share_trait`
value.share()
//~^ ERROR use of unstable library feature `share_trait`
}
fn main() {
let value = Alias;
let _ = Share::share(&value);
//~^ ERROR use of unstable library feature `share_trait`
}
@@ -0,0 +1,53 @@
error[E0658]: use of unstable library feature `share_trait`
--> $DIR/share-trait-no-feature.rs:1:5
|
LL | use std::clone::Share;
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information
= help: add `#![feature(share_trait)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `share_trait`
--> $DIR/share-trait-no-feature.rs:7:6
|
LL | impl Share for Alias {}
| ^^^^^
|
= note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information
= help: add `#![feature(share_trait)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `share_trait`
--> $DIR/share-trait-no-feature.rs:10:21
|
LL | fn share_generic<T: Share>(value: &T) -> T {
| ^^^^^
|
= note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information
= help: add `#![feature(share_trait)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `share_trait`
--> $DIR/share-trait-no-feature.rs:18:13
|
LL | let _ = Share::share(&value);
| ^^^^^^^^^^^^
|
= note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information
= help: add `#![feature(share_trait)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error[E0658]: use of unstable library feature `share_trait`
--> $DIR/share-trait-no-feature.rs:12:11
|
LL | value.share()
| ^^^^^
|
= note: see issue #156756 <https://github.com/rust-lang/rust/issues/156756> for more information
= help: add `#![feature(share_trait)]` to the crate attributes to enable
= note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0658`.
@@ -0,0 +1,19 @@
#![feature(share_trait)]
use std::clone::Share;
fn require_share<T: Share>() {}
fn main() {
require_share::<&mut i32>();
//~^ ERROR the trait bound `&mut i32: Share` is not satisfied
require_share::<String>();
//~^ ERROR the trait bound `String: Share` is not satisfied
require_share::<Vec<i32>>();
//~^ ERROR the trait bound `Vec<i32>: Share` is not satisfied
require_share::<Box<i32>>();
//~^ ERROR the trait bound `Box<i32>: Share` is not satisfied
}
@@ -0,0 +1,76 @@
error[E0277]: the trait bound `&mut i32: Share` is not satisfied
--> $DIR/share-trait-non-implementors.rs:8:21
|
LL | require_share::<&mut i32>();
| ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `&mut i32`
|
= help: the following other types implement trait `Share`:
&T
Arc<T, A>
Rc<T, A>
SyncSender<T>
std::sync::mpsc::Sender<T>
= note: `Share` is implemented for `&i32`, but not for `&mut i32`
note: required by a bound in `require_share`
--> $DIR/share-trait-non-implementors.rs:5:21
|
LL | fn require_share<T: Share>() {}
| ^^^^^ required by this bound in `require_share`
error[E0277]: the trait bound `String: Share` is not satisfied
--> $DIR/share-trait-non-implementors.rs:11:21
|
LL | require_share::<String>();
| ^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `String`
|
= help: the following other types implement trait `Share`:
&T
Arc<T, A>
Rc<T, A>
SyncSender<T>
std::sync::mpsc::Sender<T>
note: required by a bound in `require_share`
--> $DIR/share-trait-non-implementors.rs:5:21
|
LL | fn require_share<T: Share>() {}
| ^^^^^ required by this bound in `require_share`
error[E0277]: the trait bound `Vec<i32>: Share` is not satisfied
--> $DIR/share-trait-non-implementors.rs:14:21
|
LL | require_share::<Vec<i32>>();
| ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `Vec<i32>`
|
= help: the following other types implement trait `Share`:
&T
Arc<T, A>
Rc<T, A>
SyncSender<T>
std::sync::mpsc::Sender<T>
note: required by a bound in `require_share`
--> $DIR/share-trait-non-implementors.rs:5:21
|
LL | fn require_share<T: Share>() {}
| ^^^^^ required by this bound in `require_share`
error[E0277]: the trait bound `Box<i32>: Share` is not satisfied
--> $DIR/share-trait-non-implementors.rs:17:21
|
LL | require_share::<Box<i32>>();
| ^^^^^^^^ the nightly-only, unstable trait `Share` is not implemented for `Box<i32>`
|
= help: the following other types implement trait `Share`:
&T
Arc<T, A>
Rc<T, A>
SyncSender<T>
std::sync::mpsc::Sender<T>
note: required by a bound in `require_share`
--> $DIR/share-trait-non-implementors.rs:5:21
|
LL | fn require_share<T: Share>() {}
| ^^^^^ required by this bound in `require_share`
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0277`.
@@ -0,0 +1,9 @@
#![feature(share_trait)]
#[derive(Clone)]
struct Alias;
impl Share for Alias {}
//~^ ERROR cannot find trait `Share` in this scope
fn main() {}
@@ -0,0 +1,14 @@
error[E0405]: cannot find trait `Share` in this scope
--> $DIR/share-trait-not-in-prelude.rs:6:6
|
LL | impl Share for Alias {}
| ^^^^^ not found in this scope
|
help: consider importing this trait
|
LL + use std::clone::Share;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0405`.
+32
View File
@@ -0,0 +1,32 @@
//@ run-pass
#![feature(share_trait)]
use std::cell::Cell;
use std::clone::Share;
use std::rc::Rc;
trait Value {
fn get(&self) -> i32;
}
impl Value for Cell<i32> {
fn get(&self) -> i32 {
Cell::get(self)
}
}
fn main() {
let value = Rc::new(Cell::new(1));
let shared = value.share();
assert!(Rc::ptr_eq(&value, &shared));
shared.set(2);
assert_eq!(value.get(), 2);
let dyn_value: Rc<dyn Value> = Rc::new(Cell::new(3));
let shared_dyn_value = dyn_value.share();
assert!(Rc::ptr_eq(&dyn_value, &shared_dyn_value));
assert_eq!(shared_dyn_value.get(), 3);
}
@@ -0,0 +1,10 @@
#![feature(share_trait)]
use std::clone::Share;
struct NotClone;
impl Share for NotClone {}
//~^ ERROR the trait bound `NotClone: Clone` is not satisfied
fn main() {}
@@ -0,0 +1,17 @@
error[E0277]: the trait bound `NotClone: Clone` is not satisfied
--> $DIR/share-trait-requires-clone.rs:7:16
|
LL | impl Share for NotClone {}
| ^^^^^^^^ the trait `Clone` is not implemented for `NotClone`
|
note: required by a bound in `Share`
--> $SRC_DIR/core/src/clone.rs:LL:COL
help: consider annotating `NotClone` with `#[derive(Clone)]`
|
LL + #[derive(Clone)]
LL | struct NotClone;
|
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0277`.
+44
View File
@@ -0,0 +1,44 @@
//@ check-pass
#![feature(share_trait)]
extern crate core;
use core::clone::Share;
#[derive(Debug, PartialEq)]
struct Alias(u8);
impl Clone for Alias {
fn clone(&self) -> Self {
Alias(self.0 + 1)
}
}
impl Share for Alias {}
fn share_generic<T: Share>(value: &T) -> T {
value.share()
}
fn main() {
let value = Alias(1);
assert_eq!(Share::share(&value), Alias(2));
assert_eq!(std::clone::Share::share(&value), Alias(2));
assert_eq!(value.share(), Alias(2));
assert_eq!(share_generic(&value), Alias(2));
let number = 3;
let shared = &number;
let shared_again = shared.share();
let shared_fqs: &i32 = Share::share(&shared);
let shared_generic: &i32 = share_generic(&shared);
assert!(std::ptr::eq(shared, shared_again));
assert!(std::ptr::eq(shared_fqs, shared));
assert!(std::ptr::eq(shared_generic, shared));
let slice: &[i32] = &[1, 2, 3];
assert!(std::ptr::eq(slice, slice.share()));
}