Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #64927

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ci/docker/dist-x86_64-linux/build-curl.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
set -ex
source shared.sh

VERSION=7.51.0
VERSION=7.66.0

curl http://cool.haxx.se/download/curl-$VERSION.tar.bz2 | tar xjf -
curl https://rust-lang-ci-mirrors.s3-us-west-1.amazonaws.com/rustc/curl-$VERSION.tar.xz \
| xz --decompress \
| tar xf -

mkdir curl-build
cd curl-build
Expand Down
48 changes: 48 additions & 0 deletions src/liballoc/tests/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1281,3 +1281,51 @@ fn test_stable_push_pop() {
v.pop().unwrap();
assert_eq!(*v0, 13);
}

// https://github.com/rust-lang/rust/pull/49496 introduced specialization based on:
//
// ```
// unsafe impl<T: ?Sized> IsZero for *mut T {
// fn is_zero(&self) -> bool {
// (*self).is_null()
// }
// }
// ```
//
// … to call `RawVec::with_capacity_zeroed` for creating `Vec<*mut T>`,
// which is incorrect for fat pointers since `<*mut T>::is_null` only looks at the data component.
// That is, a fat pointer can be “null” without being made entirely of zero bits.
#[test]
fn vec_macro_repeating_null_raw_fat_pointer() {
let raw_dyn = &mut (|| ()) as &mut dyn Fn() as *mut dyn Fn();
let vtable = dbg!(ptr_metadata(raw_dyn));
let null_raw_dyn = ptr_from_raw_parts(std::ptr::null_mut(), vtable);
assert!(null_raw_dyn.is_null());

let vec = vec![null_raw_dyn; 1];
dbg!(ptr_metadata(vec[0]));
assert!(vec[0] == null_raw_dyn);

// Polyfill for https://github.com/rust-lang/rfcs/pull/2580

fn ptr_metadata(ptr: *mut dyn Fn()) -> *mut () {
unsafe {
std::mem::transmute::<*mut dyn Fn(), DynRepr>(ptr).vtable
}
}

fn ptr_from_raw_parts(data: *mut (), vtable: *mut()) -> *mut dyn Fn() {
unsafe {
std::mem::transmute::<DynRepr, *mut dyn Fn()>(DynRepr {
data,
vtable
})
}
}

#[repr(C)]
struct DynRepr {
data: *mut (),
vtable: *mut (),
}
}
29 changes: 27 additions & 2 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1734,20 +1734,45 @@ impl_is_zero!(char, |x| x == '\0');
impl_is_zero!(f32, |x: f32| x.to_bits() == 0);
impl_is_zero!(f64, |x: f64| x.to_bits() == 0);

unsafe impl<T: ?Sized> IsZero for *const T {
unsafe impl<T> IsZero for *const T {
#[inline]
fn is_zero(&self) -> bool {
(*self).is_null()
}
}

unsafe impl<T: ?Sized> IsZero for *mut T {
unsafe impl<T> IsZero for *mut T {
#[inline]
fn is_zero(&self) -> bool {
(*self).is_null()
}
}

// `Option<&T>`, `Option<&mut T>` and `Option<Box<T>>` are guaranteed to represent `None` as null.
// For fat pointers, the bytes that would be the pointer metadata in the `Some` variant
// are padding in the `None` variant, so ignoring them and zero-initializing instead is ok.

unsafe impl<T: ?Sized> IsZero for Option<&T> {
#[inline]
fn is_zero(&self) -> bool {
self.is_none()
}
}

unsafe impl<T: ?Sized> IsZero for Option<&mut T> {
#[inline]
fn is_zero(&self) -> bool {
self.is_none()
}
}

unsafe impl<T: ?Sized> IsZero for Option<Box<T>> {
#[inline]
fn is_zero(&self) -> bool {
self.is_none()
}
}


////////////////////////////////////////////////////////////////////////////////
// Common trait implementations for Vec
Expand Down
2 changes: 1 addition & 1 deletion src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
//! # Options and pointers ("nullable" pointers)
//!
//! Rust's pointer types must always point to a valid location; there are
//! no "null" pointers. Instead, Rust has *optional* pointers, like
//! no "null" references. Instead, Rust has *optional* pointers, like
//! the optional owned box, [`Option`]`<`[`Box<T>`]`>`.
//!
//! The following example uses [`Option`] to create an optional box of
Expand Down
43 changes: 41 additions & 2 deletions src/librustc/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,47 @@ where
```
"##,

E0495: r##"
A lifetime cannot be determined in the given situation.

Erroneous code example:

```compile_fail,E0495
fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // error!
((u,),) => u,
}
}

let y = Box::new((42,));
let x = transmute_lifetime(&y);
```

In this code, you have two ways to solve this issue:
1. Enforce that `'a` lives at least as long as `'b`.
2. Use the same lifetime requirement for both input and output values.

So for the first solution, you can do it by replacing `'a` with `'a: 'b`:

```
fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t,) { // ok!
((u,),) => u,
}
}
```

In the second you can do it by simply removing `'b` so they both use `'a`:

```
fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
match (&t,) { // ok!
((u,),) => u,
}
}
```
"##,

E0496: r##"
A lifetime name is shadowing another lifetime name. Erroneous code example:

Expand Down Expand Up @@ -2275,8 +2316,6 @@ rejected in your own crates.
E0488, // lifetime of variable does not enclose its declaration
E0489, // type/lifetime parameter not in scope here
E0490, // a value of type `..` is borrowed for too long
E0495, // cannot infer an appropriate lifetime due to conflicting
// requirements
E0566, // conflicting representation hints
E0623, // lifetime mismatch where both parameters are anonymous regions
E0628, // generators cannot have explicit parameters
Expand Down
20 changes: 19 additions & 1 deletion src/libsyntax/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,25 @@ fn deprecated_function() {}
```
"##,

E0550: r##"
More than one `deprecated` attribute has been put on an item.

Erroneous code example:

```compile_fail,E0550
#[deprecated(note = "because why not?")]
#[deprecated(note = "right?")] // error!
fn the_banished() {}
```

The `deprecated` attribute can only be present **once** on an item.

```
#[deprecated(note = "because why not, right?")]
fn the_banished() {} // ok!
```
"##,

E0552: r##"
A unrecognized representation attribute was used.

Expand Down Expand Up @@ -435,7 +454,6 @@ features in the `-Z allow_features` flag.
// rustc_deprecated attribute must be paired with either stable or unstable
// attribute
E0549,
E0550, // multiple deprecated attributes
E0551, // incorrect meta item
E0553, // multiple rustc_const_unstable attributes
// E0555, // replaced with a generic attribute input check
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | bar(foo, x)

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ LL | fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
3 changes: 2 additions & 1 deletion src/test/ui/c-variadic/variadic-ffi-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@ LL | | }

error: aborting due to 8 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0495.
For more information about an error, try `rustc --explain E0308`.
10 changes: 10 additions & 0 deletions src/test/ui/consts/issue-64662.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
enum Foo {
A = foo(), //~ ERROR: type annotations needed
B = foo(), //~ ERROR: type annotations needed
}

const fn foo<T>() -> isize {
0
}

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/consts/issue-64662.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0282]: type annotations needed
--> $DIR/issue-64662.rs:2:9
|
LL | A = foo(),
| ^^^ cannot infer type for `T`

error[E0282]: type annotations needed
--> $DIR/issue-64662.rs:3:9
|
LL | B = foo(),
| ^^^ cannot infer type for `T`

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0282`.
2 changes: 1 addition & 1 deletion src/test/ui/deprecation/deprecation-sanity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ LL | #[deprecated(since = "a", since = "b", note = "c")]

error: aborting due to 9 previous errors

Some errors have detailed explanations: E0538, E0541, E0565.
Some errors have detailed explanations: E0538, E0541, E0550, E0565.
For more information about an error, try `rustc --explain E0538`.
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | invoke(&x, |a, b| if a > b { a } else { b });

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/impl-header-lifetime-elision/dyn-trait.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ LL | fn with_dyn_debug_static<'a>(x: Box<dyn Debug + 'a>) {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ LL | | }

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/in-band-lifetimes/mismatched_trait_impl.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@ LL | x

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-16683.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | trait T<'a> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-17758.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ LL | trait Foo<'a> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
3 changes: 2 additions & 1 deletion src/test/ui/issues/issue-20831-debruijn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,5 @@ LL | impl<'a> Publisher<'a> for MyStruct<'a> {

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0308`.
Some errors have detailed explanations: E0308, E0495.
For more information about an error, try `rustc --explain E0308`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-52213.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | ((u,),) => u,

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/issues/issue-55796.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ LL | Box::new(self.in_edges(u).map(|e| e.target()))

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/issue-55394.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | impl Foo<'_> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/normalization-bounds-error.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ LL | fn visit_seq<'d, 'a: 'd>() -> <&'a () as Visitor<'d>>::Value {}

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/nll/type-alias-free-regions.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ LL | impl<'a> FromTuple<'a> for C<'a> {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | <Foo<'a>>::C

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | T::C

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ LL | fn load3<'a,'b>(ss: &'a dyn SomeTrait) -> &'b dyn SomeTrait {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/region-object-lifetime-2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | x.borrowed()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/region-object-lifetime-4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ LL | x.borrowed()

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ LL | fn d<'a,'b>(v: &'a [u8]) -> Box<dyn Foo+'b> {

error: aborting due to 4 previous errors

For more information about this error, try `rustc --explain E0621`.
Some errors have detailed explanations: E0495, E0621.
For more information about an error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-addr-of-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,4 @@ LL | let p: &'static mut usize = &mut self.cats_chased;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-addr-of-upvar-self.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | let p: &'static mut usize = &mut self.food;

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ LL | impl<'a,'b> Foo<'b> for &'a i64 {

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | impl<'a> Foo for &'a i32 {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ LL | box B(&*v) as Box<dyn X>

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ LL | fn make_object_bad<'a,'b,'c,A:SomeTrait+'a+'b>(v: A) -> Box<dyn SomeTrait +

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
1 change: 1 addition & 0 deletions src/test/ui/regions/regions-creating-enums4.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ LL | fn mk_add_bad2<'a,'b>(x: &'a Ast<'a>, y: &'a Ast<'a>, z: &Ast) -> Ast<'b> {

error: aborting due to previous error

For more information about this error, try `rustc --explain E0495`.
Loading