Merge remote-tracking branch 'origin/master' into frewsxcv-san
This commit is contained in:
commit
d482de30ea
1600 changed files with 29527 additions and 21534 deletions
|
|
@ -17,7 +17,12 @@ impl Drop for D {
|
|||
fn drop(&mut self) {
|
||||
println!("Dropping {}", self.0);
|
||||
let old = LOG.load(Ordering::SeqCst);
|
||||
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
|
||||
let _ = LOG.compare_exchange(
|
||||
old,
|
||||
old << 4 | self.0 as usize,
|
||||
Ordering::SeqCst,
|
||||
Ordering::SeqCst
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,12 @@ impl Drop for D {
|
|||
fn drop(&mut self) {
|
||||
println!("Dropping {}", self.0);
|
||||
let old = LOG.load(Ordering::SeqCst);
|
||||
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
|
||||
let _ = LOG.compare_exchange(
|
||||
old,
|
||||
old << 4 | self.0 as usize,
|
||||
Ordering::SeqCst,
|
||||
Ordering::SeqCst
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
// Ensure that we can copy out of a fixed-size array.
|
||||
//
|
||||
// (Compare with compile-fail/move-out-of-array-1.rs)
|
||||
// (Compare with ui/moves/move-out-of-array-1.rs)
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
struct C { _x: u8 }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@ LL | #![feature(const_generics)]
|
|||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
= help: consider using `min_const_generics` instead, which is more stable and complete
|
||||
|
||||
error[E0308]: mismatched types
|
||||
--> $DIR/match_arr_unknown_len.rs:6:9
|
||||
|
|
|
|||
|
|
@ -18,7 +18,12 @@ impl Drop for D {
|
|||
fn drop(&mut self) {
|
||||
println!("Dropping {}", self.0);
|
||||
let old = LOG.load(Ordering::SeqCst);
|
||||
LOG.compare_and_swap(old, old << 4 | self.0 as usize, Ordering::SeqCst);
|
||||
let _ = LOG.compare_exchange(
|
||||
old,
|
||||
old << 4 | self.0 as usize,
|
||||
Ordering::SeqCst,
|
||||
Ordering::SeqCst,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,8 +14,7 @@ impl Foo for Def {
|
|||
|
||||
pub fn test<A: Foo, B: Foo>() {
|
||||
let _array: [u32; <A as Foo>::Y];
|
||||
//~^ ERROR the trait bound `A: Foo` is not satisfied [E0277]
|
||||
//~^ ERROR generic parameters may not be used
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,11 @@
|
|||
error[E0277]: the trait bound `A: Foo` is not satisfied
|
||||
--> $DIR/associated-const-type-parameter-arrays.rs:16:23
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/associated-const-type-parameter-arrays.rs:16:24
|
||||
|
|
||||
LL | const Y: usize;
|
||||
| --------------- required by `Foo::Y`
|
||||
...
|
||||
LL | let _array: [u32; <A as Foo>::Y];
|
||||
| ^^^^^^^^^^^^^ the trait `Foo` is not implemented for `A`
|
||||
| ^ cannot perform const operation using `A`
|
||||
|
|
||||
help: consider further restricting this bound
|
||||
|
|
||||
LL | pub fn test<A: Foo + Foo, B: Foo>() {
|
||||
| ^^^^^
|
||||
= note: type parameters may not be used in const expressions
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ trait Adapter {
|
|||
struct Foo<A: Adapter> {
|
||||
adapter: A,
|
||||
links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
|
||||
//~^ ERROR: no associated item named `LINKS` found
|
||||
//~^ ERROR generic parameters may not be used in const operations
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0599]: no associated item named `LINKS` found for type parameter `A` in the current scope
|
||||
--> $DIR/associated-item-duplicate-bounds.rs:7:21
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/associated-item-duplicate-bounds.rs:7:18
|
||||
|
|
||||
LL | links: [u32; A::LINKS], // Shouldn't suggest bounds already there.
|
||||
| ^^^^^ associated item not found in `A`
|
||||
| ^^^^^^^^ cannot perform const operation using `A`
|
||||
|
|
||||
= help: items from traits can only be used if the type parameter is bounded by the trait
|
||||
= note: type parameters may not be used in const expressions
|
||||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub trait Foo<T> {
|
|||
|
||||
fn foo2<I : for<'x> Foo<&'x isize>>(
|
||||
x: <I as Foo<&isize>>::A)
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
{
|
||||
// This case is illegal because we have to instantiate `'x`, and
|
||||
// we don't know what region to instantiate it with.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub trait Foo<T> {
|
|||
|
||||
fn foo2<I : for<'x> Foo<&'x isize>>(
|
||||
x: I::A)
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
{
|
||||
// This case is illegal because we have to instantiate `'x`, and
|
||||
// we don't know what region to instantiate it with.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-fn.rs:13:8
|
||||
|
|
||||
LL | x: I::A)
|
||||
|
|
@ -6,3 +6,4 @@ LL | x: I::A)
|
|||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0212`.
|
||||
|
|
|
|||
|
|
@ -9,14 +9,14 @@ pub trait Foo<T> {
|
|||
|
||||
struct SomeStruct<I: for<'x> Foo<&'x isize>> {
|
||||
field: I::A
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
}
|
||||
|
||||
enum SomeEnum<'b, I: for<'a> Foo<&'a isize>> {
|
||||
TupleVariant(I::A),
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
StructVariant { field: I::A },
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
OkVariant(&'b usize),
|
||||
}
|
||||
|
||||
|
|
@ -33,7 +33,7 @@ struct YetAnotherStruct<'a, I: for<'x> Foo<&'x isize>> {
|
|||
struct Why<'a, 'b, 'c, 'd, 'e, 'f, 'g, 'h, 'i, 'j, 'k, 'n, 'o, 'p, 'q, 'r, 's, 't, 'u, 'v, 'w, 'x,
|
||||
'y, 'z, 'aa, I: for<'l, 'm> Foo<&'l &'m isize>> {
|
||||
field: I::A,
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:11:12
|
||||
|
|
||||
LL | field: I::A
|
||||
|
|
@ -10,7 +10,7 @@ LL | struct SomeStruct<'a, I: for<'x> Foo<&'x isize>> {
|
|||
LL | field: <I as Foo<&'a isize>>::A
|
||||
|
|
||||
|
||||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:16:18
|
||||
|
|
||||
LL | TupleVariant(I::A),
|
||||
|
|
@ -22,7 +22,7 @@ LL | enum SomeEnum<'c, 'b, I: for<'a> Foo<&'a isize>> {
|
|||
LL | TupleVariant(<I as Foo<&'c isize>>::A),
|
||||
|
|
||||
|
||||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:18:28
|
||||
|
|
||||
LL | StructVariant { field: I::A },
|
||||
|
|
@ -36,7 +36,7 @@ LL |
|
|||
LL | StructVariant { field: <I as Foo<&'c isize>>::A },
|
||||
|
|
||||
|
||||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-struct.rs:35:12
|
||||
|
|
||||
LL | field: I::A,
|
||||
|
|
@ -51,3 +51,4 @@ LL | field: <I as Foo<&'bb &'bb isize>>::A,
|
|||
|
||||
error: aborting due to 4 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0212`.
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub trait Foo<T> {
|
|||
|
||||
trait SomeTrait<I : for<'x> Foo<&'x isize>> {
|
||||
fn some_method(&self, arg: <I as Foo<&isize>>::A);
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
}
|
||||
|
||||
trait AnotherTrait<I : for<'x> Foo<&'x isize>> {
|
||||
|
|
@ -30,7 +30,7 @@ struct Peach<X>(std::marker::PhantomData<X>);
|
|||
|
||||
impl<X: for<'a> Banana<'a>> Peach<X> {
|
||||
fn mango(&self) -> <X as Banana<'_>>::Assoc {
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ pub trait Foo<T> {
|
|||
|
||||
trait SomeTrait<I : for<'x> Foo<&'x isize>> {
|
||||
fn some_method(&self, arg: I::A);
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
}
|
||||
|
||||
trait AnotherTrait<I : for<'x> Foo<&'x isize>> {
|
||||
|
|
@ -30,7 +30,7 @@ struct Peach<X>(std::marker::PhantomData<X>);
|
|||
|
||||
impl<X: for<'a> Banana<'a>> Peach<X> {
|
||||
fn mango(&self) -> X::Assoc {
|
||||
//~^ ERROR cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
//~^ ERROR cannot use the associated type of a trait with uninferred generic parameters
|
||||
Default::default()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:13:32
|
||||
|
|
||||
LL | fn some_method(&self, arg: I::A);
|
||||
| ^^^^ help: use a fully qualified path with inferred lifetimes: `<I as Foo<&isize>>::A`
|
||||
|
||||
error[E0212]: cannot extract an associated type from a higher-ranked trait bound in this context
|
||||
error[E0212]: cannot use the associated type of a trait with uninferred generic parameters
|
||||
--> $DIR/associated-types-project-from-hrtb-in-trait-method.rs:32:24
|
||||
|
|
||||
LL | fn mango(&self) -> X::Assoc {
|
||||
|
|
@ -12,3 +12,4 @@ LL | fn mango(&self) -> X::Assoc {
|
|||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0212`.
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
// the trait definition if there is no default method and for every impl,
|
||||
// `Self` does implement `Get`.
|
||||
//
|
||||
// See also compile-fail tests associated-types-no-suitable-supertrait
|
||||
// See also tests associated-types-no-suitable-supertrait
|
||||
// and associated-types-no-suitable-supertrait-2, which show how small
|
||||
// variants of the code below can fail.
|
||||
|
||||
|
|
|
|||
|
|
@ -24,13 +24,13 @@ impl Tr for u32 {
|
|||
// ...but not in an impl that redefines one of the types.
|
||||
impl Tr for bool {
|
||||
type A = Box<Self::B>;
|
||||
//~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
}
|
||||
// (the error is shown twice for some reason)
|
||||
|
||||
impl Tr for usize {
|
||||
type B = &'static Self::A;
|
||||
//~^ ERROR type mismatch resolving `<usize as Tr>::A == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _`
|
||||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
--> $DIR/defaults-cyclic-fail-1.rs:26:5
|
||||
|
|
||||
LL | type A = Box<Self::B>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _`
|
||||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
--> $DIR/defaults-cyclic-fail-1.rs:32:5
|
||||
|
|
||||
LL | type B = &'static Self::A;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@ impl Tr for u32 {
|
|||
|
||||
impl Tr for bool {
|
||||
type A = Box<Self::B>;
|
||||
//~^ ERROR type mismatch resolving `<bool as Tr>::B == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
}
|
||||
// (the error is shown twice for some reason)
|
||||
|
||||
impl Tr for usize {
|
||||
type B = &'static Self::A;
|
||||
//~^ ERROR type mismatch resolving `<usize as Tr>::A == _`
|
||||
//~^ ERROR overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
error[E0271]: type mismatch resolving `<bool as Tr>::B == _`
|
||||
error[E0275]: overflow evaluating the requirement `<bool as Tr>::B == _`
|
||||
--> $DIR/defaults-cyclic-fail-2.rs:27:5
|
||||
|
|
||||
LL | type A = Box<Self::B>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error[E0271]: type mismatch resolving `<usize as Tr>::A == _`
|
||||
error[E0275]: overflow evaluating the requirement `<usize as Tr>::A == _`
|
||||
--> $DIR/defaults-cyclic-fail-2.rs:33:5
|
||||
|
|
||||
LL | type B = &'static Self::A;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ cyclic type of infinite size
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0271`.
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ error[E0277]: the size for values of type `[u8]` cannot be known at compilation
|
|||
LL | type Ty = Vec<[u8]>;
|
||||
| ^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
||||
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
||||
|
|
||||
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
|
||||
| - required by this bound in `Vec`
|
||||
|
|
|
|||
29
src/test/ui/associated-types/impl-wf-cycle-1.rs
Normal file
29
src/test/ui/associated-types/impl-wf-cycle-1.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Regression test for #79714
|
||||
|
||||
trait Baz {}
|
||||
impl Baz for () {}
|
||||
impl<T> Baz for (T,) {}
|
||||
|
||||
trait Fiz {}
|
||||
impl Fiz for bool {}
|
||||
|
||||
trait Grault {
|
||||
type A;
|
||||
type B;
|
||||
}
|
||||
|
||||
impl<T: Grault> Grault for (T,)
|
||||
where
|
||||
Self::A: Baz,
|
||||
Self::B: Fiz,
|
||||
{
|
||||
type A = ();
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
type B = bool;
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
}
|
||||
//~^^^^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
|
||||
fn main() {
|
||||
let x: <(_,) as Grault>::A = ();
|
||||
}
|
||||
39
src/test/ui/associated-types/impl-wf-cycle-1.stderr
Normal file
39
src/test/ui/associated-types/impl-wf-cycle-1.stderr
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:15:1
|
||||
|
|
||||
LL | / impl<T: Grault> Grault for (T,)
|
||||
LL | | where
|
||||
LL | | Self::A: Baz,
|
||||
LL | | Self::B: Fiz,
|
||||
... |
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:20:5
|
||||
|
|
||||
LL | type A = ();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-1.rs:22:5
|
||||
|
|
||||
LL | type B = bool;
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
= note: 1 redundant requirements hidden
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
16
src/test/ui/associated-types/impl-wf-cycle-2.rs
Normal file
16
src/test/ui/associated-types/impl-wf-cycle-2.rs
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
// Regression test for #79714
|
||||
|
||||
trait Grault {
|
||||
type A;
|
||||
}
|
||||
|
||||
impl<T: Grault> Grault for (T,)
|
||||
where
|
||||
Self::A: Copy,
|
||||
{
|
||||
type A = ();
|
||||
//~^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
}
|
||||
//~^^^^^^^ ERROR overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
|
||||
fn main() {}
|
||||
25
src/test/ui/associated-types/impl-wf-cycle-2.stderr
Normal file
25
src/test/ui/associated-types/impl-wf-cycle-2.stderr
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-2.rs:7:1
|
||||
|
|
||||
LL | / impl<T: Grault> Grault for (T,)
|
||||
LL | | where
|
||||
LL | | Self::A: Copy,
|
||||
LL | | {
|
||||
LL | | type A = ();
|
||||
LL | |
|
||||
LL | | }
|
||||
| |_^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error[E0275]: overflow evaluating the requirement `<(T,) as Grault>::A == _`
|
||||
--> $DIR/impl-wf-cycle-2.rs:11:5
|
||||
|
|
||||
LL | type A = ();
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= note: required because of the requirements on the impl of `Grault` for `(T,)`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0275`.
|
||||
14
src/test/ui/associated-types/issue-23595-1.rs
Normal file
14
src/test/ui/associated-types/issue-23595-1.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#![feature(associated_type_defaults)]
|
||||
|
||||
use std::ops::Index;
|
||||
|
||||
trait Hierarchy {
|
||||
type Value;
|
||||
type ChildKey;
|
||||
type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
|
||||
//~^ ERROR: the value of the associated types
|
||||
|
||||
fn data(&self) -> Option<(Self::Value, Self::Children)>;
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
16
src/test/ui/associated-types/issue-23595-1.stderr
Normal file
16
src/test/ui/associated-types/issue-23595-1.stderr
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
error[E0191]: the value of the associated types `ChildKey` (from trait `Hierarchy`), `Children` (from trait `Hierarchy`), `Value` (from trait `Hierarchy`) must be specified
|
||||
--> $DIR/issue-23595-1.rs:8:58
|
||||
|
|
||||
LL | type Value;
|
||||
| ----------- `Value` defined here
|
||||
LL | type ChildKey;
|
||||
| -------------- `ChildKey` defined here
|
||||
LL | type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
|
||||
| -----------------------------------------------------^^^^^^^^^--
|
||||
| | |
|
||||
| | help: specify the associated types: `Hierarchy<Value = Type, ChildKey = Type, Children = Type>`
|
||||
| `Children` defined here
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0191`.
|
||||
19
src/test/ui/associated-types/issue-27675-unchecked-bounds.rs
Normal file
19
src/test/ui/associated-types/issue-27675-unchecked-bounds.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/// The compiler previously did not properly check the bound of `From` when it was used from type
|
||||
/// of the dyn trait object (use in `copy_any` below). Since the associated type is under user
|
||||
/// control in this usage, the compiler could be tricked to believe any type implemented any trait.
|
||||
/// This would ICE, except for pure marker traits like `Copy`. It did not require providing an
|
||||
/// instance of the dyn trait type, only name said type.
|
||||
trait Setup {
|
||||
type From: Copy;
|
||||
}
|
||||
|
||||
fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
|
||||
*from
|
||||
}
|
||||
|
||||
pub fn copy_any<T>(t: &T) -> T {
|
||||
copy::<dyn Setup<From=T>>(t)
|
||||
//~^ ERROR the trait bound `T: Copy` is not satisfied
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
error[E0277]: the trait bound `T: Copy` is not satisfied
|
||||
--> $DIR/issue-27675-unchecked-bounds.rs:15:31
|
||||
|
|
||||
LL | fn copy<U: Setup + ?Sized>(from: &U::From) -> U::From {
|
||||
| ----- required by this bound in `copy`
|
||||
...
|
||||
LL | copy::<dyn Setup<From=T>>(t)
|
||||
| ^ the trait `Copy` is not implemented for `T`
|
||||
|
|
||||
help: consider restricting type parameter `T`
|
||||
|
|
||||
LL | pub fn copy_any<T: Copy>(t: &T) -> T {
|
||||
| ^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -2,7 +2,7 @@ error[E0506]: cannot assign to `*x` because it is borrowed
|
|||
--> $DIR/issue-74072-lifetime-name-annotations.rs:9:5
|
||||
|
|
||||
LL | pub async fn async_fn(x: &mut i32) -> &i32 {
|
||||
| - let's call the lifetime of this reference `'1`
|
||||
| - let's call the lifetime of this reference `'1`
|
||||
LL | let y = &*x;
|
||||
| --- borrow of `*x` occurs here
|
||||
LL | *x += 1;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
// edition:2018
|
||||
//
|
||||
// Regression test for issue #75785
|
||||
// Tests that we don't point to a confusing named
|
||||
// region when emitting a diagnostic
|
||||
|
||||
pub async fn async_fn(x: &mut i32) -> (&i32, &i32) {
|
||||
let y = &*x;
|
||||
*x += 1; //~ ERROR cannot assign to
|
||||
(&32, y)
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
error[E0506]: cannot assign to `*x` because it is borrowed
|
||||
--> $DIR/issue-75785-confusing-named-region.rs:9:5
|
||||
|
|
||||
LL | pub async fn async_fn(x: &mut i32) -> (&i32, &i32) {
|
||||
| - let's call the lifetime of this reference `'1`
|
||||
LL | let y = &*x;
|
||||
| --- borrow of `*x` occurs here
|
||||
LL | *x += 1;
|
||||
| ^^^^^^^ assignment to borrowed `*x` occurs here
|
||||
LL | (&32, y)
|
||||
| -------- returning this value requires that `*x` is borrowed for `'1`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0506`.
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0573]: expected type, found built-in attribute `feature`
|
||||
--> $DIR/issue-78654.rs:10:15
|
||||
--> $DIR/issue-78654.rs:9:15
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^^^^^^^ not a type
|
||||
|
||||
error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/issue-78654.rs:10:12
|
||||
--> $DIR/issue-78654.rs:9:12
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^ unconstrained const parameter
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0573]: expected type, found built-in attribute `feature`
|
||||
--> $DIR/issue-78654.rs:10:15
|
||||
--> $DIR/issue-78654.rs:9:15
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^^^^^^^ not a type
|
||||
|
||||
error[E0207]: the const parameter `H` is not constrained by the impl trait, self type, or predicates
|
||||
--> $DIR/issue-78654.rs:10:12
|
||||
--> $DIR/issue-78654.rs:9:12
|
||||
|
|
||||
LL | impl<const H: feature> Foo {
|
||||
| ^ unconstrained const parameter
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Foo;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ error[E0277]: the size for values of type `dyn Trait` cannot be known at compila
|
|||
LL | let x: Vec<dyn Trait + Sized> = Vec::new();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^ doesn't have a size known at compile-time
|
||||
|
|
||||
::: $SRC_DIR/alloc/src/vec.rs:LL:COL
|
||||
::: $SRC_DIR/alloc/src/vec/mod.rs:LL:COL
|
||||
|
|
||||
LL | pub struct Vec<T, #[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global> {
|
||||
| - required by this bound in `Vec`
|
||||
|
|
|
|||
9
src/test/ui/binding/const-param.full.stderr
Normal file
9
src/test/ui/binding/const-param.full.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0158]: const parameters cannot be referenced in patterns
|
||||
--> $DIR/const-param.rs:8:9
|
||||
|
|
||||
LL | N => {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0158`.
|
||||
9
src/test/ui/binding/const-param.min.stderr
Normal file
9
src/test/ui/binding/const-param.min.stderr
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
error[E0158]: const parameters cannot be referenced in patterns
|
||||
--> $DIR/const-param.rs:8:9
|
||||
|
|
||||
LL | N => {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0158`.
|
||||
|
|
@ -1,6 +1,7 @@
|
|||
// Identifier pattern referring to a const generic parameter is an error (issue #68853).
|
||||
|
||||
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
|
||||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
|
||||
fn check<const N: usize>() {
|
||||
match 1 {
|
||||
|
|
|
|||
|
|
@ -1,19 +0,0 @@
|
|||
warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/const-param.rs:3:12
|
||||
|
|
||||
LL | #![feature(const_generics)]
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
|
||||
= help: consider using `min_const_generics` instead, which is more stable and complete
|
||||
|
||||
error[E0158]: const parameters cannot be referenced in patterns
|
||||
--> $DIR/const-param.rs:7:9
|
||||
|
|
||||
LL | N => {}
|
||||
| ^
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0158`.
|
||||
11
src/test/ui/binop/issue-77910-1.rs
Normal file
11
src/test/ui/binop/issue-77910-1.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn foo(s: &i32) -> &i32 {
|
||||
let xs;
|
||||
xs
|
||||
}
|
||||
fn main() {
|
||||
let y;
|
||||
// we shouldn't ice with the bound var here.
|
||||
assert_eq!(foo, y);
|
||||
//~^ ERROR binary operation `==` cannot be applied to type
|
||||
//~| ERROR `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
|
||||
}
|
||||
26
src/test/ui/binop/issue-77910-1.stderr
Normal file
26
src/test/ui/binop/issue-77910-1.stderr
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
|
||||
--> $DIR/issue-77910-1.rs:8:5
|
||||
|
|
||||
LL | assert_eq!(foo, y);
|
||||
| ^^^^^^^^^^^^^^^^^^^
|
||||
| |
|
||||
| for<'r> fn(&'r i32) -> &'r i32 {foo}
|
||||
| _
|
||||
|
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error[E0277]: `for<'r> fn(&'r i32) -> &'r i32 {foo}` doesn't implement `Debug`
|
||||
--> $DIR/issue-77910-1.rs:8:5
|
||||
|
|
||||
LL | assert_eq!(foo, y);
|
||||
| ^^^^^^^^^^^^^^^^^^^ `for<'r> fn(&'r i32) -> &'r i32 {foo}` cannot be formatted using `{:?}` because it doesn't implement `Debug`
|
||||
|
|
||||
= help: the trait `Debug` is not implemented for `for<'r> fn(&'r i32) -> &'r i32 {foo}`
|
||||
= note: required because of the requirements on the impl of `Debug` for `&for<'r> fn(&'r i32) -> &'r i32 {foo}`
|
||||
= note: required by `std::fmt::Debug::fmt`
|
||||
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
Some errors have detailed explanations: E0277, E0369.
|
||||
For more information about an error, try `rustc --explain E0277`.
|
||||
9
src/test/ui/binop/issue-77910-2.rs
Normal file
9
src/test/ui/binop/issue-77910-2.rs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
fn foo(s: &i32) -> &i32 {
|
||||
let xs;
|
||||
xs
|
||||
}
|
||||
fn main() {
|
||||
let y;
|
||||
if foo == y {}
|
||||
//~^ ERROR binary operation `==` cannot be applied to type
|
||||
}
|
||||
11
src/test/ui/binop/issue-77910-2.stderr
Normal file
11
src/test/ui/binop/issue-77910-2.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error[E0369]: binary operation `==` cannot be applied to type `for<'r> fn(&'r i32) -> &'r i32 {foo}`
|
||||
--> $DIR/issue-77910-2.rs:7:12
|
||||
|
|
||||
LL | if foo == y {}
|
||||
| --- ^^ - _
|
||||
| |
|
||||
| for<'r> fn(&'r i32) -> &'r i32 {foo}
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0369`.
|
||||
|
|
@ -23,7 +23,7 @@ error[E0499]: cannot borrow `x` as mutable more than once at a time
|
|||
--> $DIR/borrowck-mut-borrow-linear-errors.rs:12:30
|
||||
|
|
||||
LL | _ => { addr.push(&mut x); }
|
||||
| ^^^^^^ mutable borrow starts here in previous iteration of loop
|
||||
| ^^^^^^ `x` was mutably borrowed here in the previous iteration of the loop
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
|
|||
LL | (self.func)(arg)
|
||||
| ------------^^^-
|
||||
| | |
|
||||
| | mutable borrow starts here in previous iteration of loop
|
||||
| | `*arg` was mutably borrowed here in the previous iteration of the loop
|
||||
| argument requires that `*arg` is borrowed for `'a`
|
||||
|
||||
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
|
||||
|
|
@ -27,7 +27,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
|
|||
LL | (self.func)(arg)
|
||||
| ------------^^^-
|
||||
| | |
|
||||
| | mutable borrow starts here in previous iteration of loop
|
||||
| | `*arg` was mutably borrowed here in the previous iteration of the loop
|
||||
| argument requires that `*arg` is borrowed for `'a`
|
||||
|
||||
error[E0499]: cannot borrow `*arg` as mutable more than once at a time
|
||||
|
|
@ -39,7 +39,7 @@ LL | impl<'a, T : 'a> FuncWrapper<'a, T> {
|
|||
LL | (self.func)(arg)
|
||||
| ------------^^^-
|
||||
| | |
|
||||
| | mutable borrow starts here in previous iteration of loop
|
||||
| | `*arg` was mutably borrowed here in the previous iteration of the loop
|
||||
| argument requires that `*arg` is borrowed for `'a`
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error[E0499]: cannot borrow `foo` as mutable more than once at a time
|
|||
--> $DIR/two-phase-across-loop.rs:17:22
|
||||
|
|
||||
LL | strings.push(foo.get_string());
|
||||
| ^^^ mutable borrow starts here in previous iteration of loop
|
||||
| ^^^ `foo` was mutably borrowed here in the previous iteration of the loop
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,86 @@
|
|||
// Test that arrays are completely captured by closures by relying on the borrow check diagnostics
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
|
||||
fn arrays_1() {
|
||||
let mut arr = [1, 2, 3, 4, 5];
|
||||
|
||||
let mut c = || {
|
||||
arr[0] += 10;
|
||||
};
|
||||
|
||||
// c will capture `arr` completely, therefore another index into the
|
||||
// array can't be modified here
|
||||
arr[1] += 10;
|
||||
//~^ ERROR: cannot use `arr` because it was mutably borrowed
|
||||
//~| ERROR: cannot use `arr[_]` because it was mutably borrowed
|
||||
c();
|
||||
}
|
||||
|
||||
fn arrays_2() {
|
||||
let mut arr = [1, 2, 3, 4, 5];
|
||||
|
||||
let c = || {
|
||||
println!("{:#?}", &arr[3..4]);
|
||||
};
|
||||
|
||||
// c will capture `arr` completely, therefore another index into the
|
||||
// array can't be modified here
|
||||
arr[1] += 10;
|
||||
//~^ ERROR: cannot assign to `arr[_]` because it is borrowed
|
||||
c();
|
||||
}
|
||||
|
||||
fn arrays_3() {
|
||||
let mut arr = [1, 2, 3, 4, 5];
|
||||
|
||||
let c = || {
|
||||
println!("{}", arr[3]);
|
||||
};
|
||||
|
||||
// c will capture `arr` completely, therefore another index into the
|
||||
// array can't be modified here
|
||||
arr[1] += 10;
|
||||
//~^ ERROR: cannot assign to `arr[_]` because it is borrowed
|
||||
c();
|
||||
}
|
||||
|
||||
fn arrays_4() {
|
||||
let mut arr = [1, 2, 3, 4, 5];
|
||||
|
||||
let mut c = || {
|
||||
arr[1] += 10;
|
||||
};
|
||||
|
||||
// c will capture `arr` completely, therefore we cannot borrow another index
|
||||
// into the array.
|
||||
println!("{}", arr[3]);
|
||||
//~^ ERROR: cannot use `arr` because it was mutably borrowed
|
||||
//~| ERROR: cannot borrow `arr[_]` as immutable because it is also borrowed as mutable
|
||||
|
||||
c();
|
||||
}
|
||||
|
||||
fn arrays_5() {
|
||||
let mut arr = [1, 2, 3, 4, 5];
|
||||
|
||||
let mut c = || {
|
||||
arr[1] += 10;
|
||||
};
|
||||
|
||||
// c will capture `arr` completely, therefore we cannot borrow other indecies
|
||||
// into the array.
|
||||
println!("{:#?}", &arr[3..2]);
|
||||
//~^ ERROR: cannot borrow `arr` as immutable because it is also borrowed as mutable
|
||||
|
||||
c();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
arrays_1();
|
||||
arrays_2();
|
||||
arrays_3();
|
||||
arrays_4();
|
||||
arrays_5();
|
||||
}
|
||||
|
|
@ -0,0 +1,111 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/arrays.rs:3:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
error[E0503]: cannot use `arr` because it was mutably borrowed
|
||||
--> $DIR/arrays.rs:15:5
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- borrow of `arr` occurs here
|
||||
LL | arr[0] += 10;
|
||||
| --- borrow occurs due to use of `arr` in closure
|
||||
...
|
||||
LL | arr[1] += 10;
|
||||
| ^^^^^^ use of borrowed `arr`
|
||||
...
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0503]: cannot use `arr[_]` because it was mutably borrowed
|
||||
--> $DIR/arrays.rs:15:5
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- borrow of `arr` occurs here
|
||||
LL | arr[0] += 10;
|
||||
| --- borrow occurs due to use of `arr` in closure
|
||||
...
|
||||
LL | arr[1] += 10;
|
||||
| ^^^^^^^^^^^^ use of borrowed `arr`
|
||||
...
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `arr[_]` because it is borrowed
|
||||
--> $DIR/arrays.rs:30:5
|
||||
|
|
||||
LL | let c = || {
|
||||
| -- borrow of `arr[_]` occurs here
|
||||
LL | println!("{:#?}", &arr[3..4]);
|
||||
| --- borrow occurs due to use in closure
|
||||
...
|
||||
LL | arr[1] += 10;
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `arr[_]` occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `arr[_]` because it is borrowed
|
||||
--> $DIR/arrays.rs:44:5
|
||||
|
|
||||
LL | let c = || {
|
||||
| -- borrow of `arr[_]` occurs here
|
||||
LL | println!("{}", arr[3]);
|
||||
| --- borrow occurs due to use in closure
|
||||
...
|
||||
LL | arr[1] += 10;
|
||||
| ^^^^^^^^^^^^ assignment to borrowed `arr[_]` occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0503]: cannot use `arr` because it was mutably borrowed
|
||||
--> $DIR/arrays.rs:58:20
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- borrow of `arr` occurs here
|
||||
LL | arr[1] += 10;
|
||||
| --- borrow occurs due to use of `arr` in closure
|
||||
...
|
||||
LL | println!("{}", arr[3]);
|
||||
| ^^^^^^ use of borrowed `arr`
|
||||
...
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `arr[_]` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/arrays.rs:58:20
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- mutable borrow occurs here
|
||||
LL | arr[1] += 10;
|
||||
| --- first borrow occurs due to use of `arr` in closure
|
||||
...
|
||||
LL | println!("{}", arr[3]);
|
||||
| ^^^^^^ immutable borrow occurs here
|
||||
...
|
||||
LL | c();
|
||||
| - mutable borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `arr` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/arrays.rs:74:24
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- mutable borrow occurs here
|
||||
LL | arr[1] += 10;
|
||||
| --- first borrow occurs due to use of `arr` in closure
|
||||
...
|
||||
LL | println!("{:#?}", &arr[3..2]);
|
||||
| ^^^ immutable borrow occurs here
|
||||
...
|
||||
LL | c();
|
||||
| - mutable borrow later used here
|
||||
|
||||
error: aborting due to 7 previous errors; 1 warning emitted
|
||||
|
||||
Some errors have detailed explanations: E0502, E0503, E0506.
|
||||
For more information about an error, try `rustc --explain E0502`.
|
||||
|
|
@ -0,0 +1,65 @@
|
|||
// Test borrow checker when we precise capture when using boxes
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
|
||||
struct MetaData { x: String, name: String }
|
||||
struct Data { m: MetaData }
|
||||
struct BoxedData(Box<Data>);
|
||||
struct EvenMoreBoxedData(Box<BoxedData>);
|
||||
|
||||
// Check diagnostics when the same path is mutated both inside and outside the closure
|
||||
fn box_1() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let mut c = || {
|
||||
e.0.0.m.x = format!("not-x");
|
||||
};
|
||||
|
||||
e.0.0.m.x = format!("not-x");
|
||||
//~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed
|
||||
c();
|
||||
}
|
||||
|
||||
// Check diagnostics when a path is mutated inside a closure while attempting to read it outside
|
||||
// the closure.
|
||||
fn box_2() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let mut c = || {
|
||||
e.0.0.m.x = format!("not-x");
|
||||
};
|
||||
|
||||
println!("{}", e.0.0.m.x);
|
||||
//~^ ERROR: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable
|
||||
c();
|
||||
}
|
||||
|
||||
// Check diagnostics when a path is read inside a closure while attempting to mutate it outside
|
||||
// the closure.
|
||||
fn box_3() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let c = || {
|
||||
println!("{}", e.0.0.m.x);
|
||||
};
|
||||
|
||||
e.0.0.m.x = format!("not-x");
|
||||
//~^ ERROR: cannot assign to `e.0.0.m.x` because it is borrowed
|
||||
c();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
box_1();
|
||||
box_2();
|
||||
box_3();
|
||||
}
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/box.rs:3:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
|
||||
--> $DIR/box.rs:22:5
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- borrow of `e.0.0.m.x` occurs here
|
||||
LL | e.0.0.m.x = format!("not-x");
|
||||
| - borrow occurs due to use in closure
|
||||
...
|
||||
LL | e.0.0.m.x = format!("not-x");
|
||||
| ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error[E0502]: cannot borrow `e.0.0.m.x` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/box.rs:39:20
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- mutable borrow occurs here
|
||||
LL | e.0.0.m.x = format!("not-x");
|
||||
| - first borrow occurs due to use of `e.0.0.m.x` in closure
|
||||
...
|
||||
LL | println!("{}", e.0.0.m.x);
|
||||
| ^^^^^^^^^ immutable borrow occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - mutable borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `e.0.0.m.x` because it is borrowed
|
||||
--> $DIR/box.rs:56:5
|
||||
|
|
||||
LL | let c = || {
|
||||
| -- borrow of `e.0.0.m.x` occurs here
|
||||
LL | println!("{}", e.0.0.m.x);
|
||||
| - borrow occurs due to use in closure
|
||||
...
|
||||
LL | e.0.0.m.x = format!("not-x");
|
||||
| ^^^^^^^^^ assignment to borrowed `e.0.0.m.x` occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - borrow later used here
|
||||
|
||||
error: aborting due to 3 previous errors; 1 warning emitted
|
||||
|
||||
Some errors have detailed explanations: E0502, E0506.
|
||||
For more information about an error, try `rustc --explain E0502`.
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// Test that when a borrow checker diagnostics are emitted, it's as precise
|
||||
// as the capture by the closure.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
#![allow(unused)]
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
struct Wrapper {
|
||||
p: Point,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
|
||||
|
||||
let mut c = || {
|
||||
w.p.x += 20;
|
||||
};
|
||||
|
||||
let py = &mut w.p.x;
|
||||
//~^ ERROR: cannot borrow `w.p.x` as mutable more than once at a time
|
||||
c();
|
||||
|
||||
*py = 20
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/multilevel-path.rs:4:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
error[E0499]: cannot borrow `w.p.x` as mutable more than once at a time
|
||||
--> $DIR/multilevel-path.rs:23:14
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- first mutable borrow occurs here
|
||||
LL | w.p.x += 20;
|
||||
| - first borrow occurs due to use of `w.p.x` in closure
|
||||
...
|
||||
LL | let py = &mut w.p.x;
|
||||
| ^^^^^^^^^^ second mutable borrow occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - first borrow later used here
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0499`.
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
// Test that borrow checker error is accurate and that min capture pass of the
|
||||
// closure analysis is working as expected.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut p = Point { x: 10, y: 20 };
|
||||
|
||||
// `p` is captured via mutable borrow.
|
||||
let mut c = || {
|
||||
p.x += 10;
|
||||
println!("{:?}", p);
|
||||
};
|
||||
|
||||
|
||||
println!("{:?}", p);
|
||||
//~^ ERROR: cannot borrow `p` as immutable because it is also borrowed as mutable
|
||||
c();
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/simple-struct-min-capture.rs:4:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
error[E0502]: cannot borrow `p` as immutable because it is also borrowed as mutable
|
||||
--> $DIR/simple-struct-min-capture.rs:23:22
|
||||
|
|
||||
LL | let mut c = || {
|
||||
| -- mutable borrow occurs here
|
||||
LL | p.x += 10;
|
||||
| - first borrow occurs due to use of `p` in closure
|
||||
...
|
||||
LL | println!("{:?}", p);
|
||||
| ^ immutable borrow occurs here
|
||||
LL |
|
||||
LL | c();
|
||||
| - mutable borrow later used here
|
||||
|
||||
error: aborting due to previous error; 1 warning emitted
|
||||
|
||||
For more information about this error, try `rustc --explain E0502`.
|
||||
97
src/test/ui/closures/2229_closure_analysis/run_pass/box.rs
Normal file
97
src/test/ui/closures/2229_closure_analysis/run_pass/box.rs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// run-pass
|
||||
|
||||
// Test precise capture when using boxes
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
|
||||
struct MetaData { x: String, name: String }
|
||||
struct Data { m: MetaData }
|
||||
struct BoxedData(Box<Data>);
|
||||
struct EvenMoreBoxedData(Box<BoxedData>);
|
||||
|
||||
// Mutate disjoint paths, one inside one outside the closure
|
||||
fn box_1() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let mut c = || {
|
||||
e.0.0.m.x = format!("not-x");
|
||||
};
|
||||
|
||||
e.0.0.m.name = format!("not-name");
|
||||
c();
|
||||
}
|
||||
|
||||
// Mutate a path inside the closure and read a disjoint path outside the closure
|
||||
fn box_2() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let mut c = || {
|
||||
e.0.0.m.x = format!("not-x");
|
||||
};
|
||||
|
||||
println!("{}", e.0.0.m.name);
|
||||
c();
|
||||
}
|
||||
|
||||
// Read a path inside the closure and mutate a disjoint path outside the closure
|
||||
fn box_3() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let mut e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let c = || {
|
||||
println!("{}", e.0.0.m.name);
|
||||
};
|
||||
|
||||
e.0.0.m.x = format!("not-x");
|
||||
c();
|
||||
}
|
||||
|
||||
// Read disjoint paths, one inside the closure and one outside the closure.
|
||||
fn box_4() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let c = || {
|
||||
println!("{}", e.0.0.m.name);
|
||||
};
|
||||
|
||||
println!("{}", e.0.0.m.x);
|
||||
c();
|
||||
}
|
||||
|
||||
// Read the same path, once inside the closure and once outside the closure.
|
||||
fn box_5() {
|
||||
let m = MetaData { x: format!("x"), name: format!("name") };
|
||||
let d = Data { m };
|
||||
let b = BoxedData(Box::new(d));
|
||||
let e = EvenMoreBoxedData(Box::new(b));
|
||||
|
||||
let c = || {
|
||||
println!("{}", e.0.0.m.name);
|
||||
};
|
||||
|
||||
println!("{}", e.0.0.m.name);
|
||||
c();
|
||||
}
|
||||
|
||||
fn main() {
|
||||
box_1();
|
||||
box_2();
|
||||
box_3();
|
||||
box_4();
|
||||
box_5();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/box.rs:5:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
// run-pass
|
||||
|
||||
// Test that we can immutably borrow field of an instance of a structure from within a closure,
|
||||
// while having a mutable borrow to another field of the same instance outside the closure.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut p = Point { x: 10, y: 10 };
|
||||
|
||||
let c = || {
|
||||
println!("{}", p.x);
|
||||
};
|
||||
|
||||
// `c` should only capture `p.x`, therefore mutating `p.y` is allowed.
|
||||
let py = &mut p.y;
|
||||
|
||||
c();
|
||||
*py = 20;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/capture-disjoint-field-struct.rs:6:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
// run-pass
|
||||
|
||||
// Test that we can mutate an element of a tuple from within a closure
|
||||
// while immutably borrowing another element of the same tuple outside the closure.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
fn main() {
|
||||
let mut t = (10, 10);
|
||||
|
||||
let mut c = || {
|
||||
let t1 = &mut t.1;
|
||||
*t1 = 20;
|
||||
};
|
||||
|
||||
// Test that `c` only captures t.1, therefore reading t.0 is allowed.
|
||||
println!("{}", t.0);
|
||||
c();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/capture-disjoint-field-tuple-mut.rs:6:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
// run-pass
|
||||
|
||||
// Test that we can immutably borrow an element of a tuple from within a closure,
|
||||
// while having a mutable borrow to another element of the same tuple outside the closure.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
fn main() {
|
||||
let mut t = (10, 10);
|
||||
|
||||
let c = || {
|
||||
println!("{}", t.0);
|
||||
};
|
||||
|
||||
// `c` only captures t.0, therefore mutating t.1 is allowed.
|
||||
let t1 = &mut t.1;
|
||||
|
||||
c();
|
||||
*t1 = 20;
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/capture-disjoint-field-tuple.rs:6:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
// run-pass
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
// Tests that if a closure uses indivual fields of the same object
|
||||
// then that case is handled properly.
|
||||
|
||||
#![allow(unused)]
|
||||
|
||||
struct Struct {
|
||||
x: i32,
|
||||
y: i32,
|
||||
s: String,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut s = Struct { x: 10, y: 10, s: String::new() };
|
||||
|
||||
let mut c = {
|
||||
s.x += 10;
|
||||
s.y += 42;
|
||||
s.s = String::from("new");
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/disjoint-capture-in-same-closure.rs:3:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
// run-pass
|
||||
|
||||
// Test disjoint capture within an impl block
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
struct Filter {
|
||||
div: i32,
|
||||
}
|
||||
impl Filter {
|
||||
fn allowed(&self, x: i32) -> bool {
|
||||
x % self.div == 1
|
||||
}
|
||||
}
|
||||
|
||||
struct Data {
|
||||
filter: Filter,
|
||||
list: Vec<i32>,
|
||||
}
|
||||
impl Data {
|
||||
fn update(&mut self) {
|
||||
// The closure passed to filter only captures self.filter,
|
||||
// therefore mutating self.list is allowed.
|
||||
self.list.retain(
|
||||
|v| self.filter.allowed(*v),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut d = Data { filter: Filter { div: 3 }, list: Vec::new() };
|
||||
|
||||
for i in 1..10 {
|
||||
d.list.push(i);
|
||||
}
|
||||
|
||||
d.update();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/filter-on-struct-member.rs:5:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
// run-pass
|
||||
|
||||
// Test that closures can catpure paths that are more precise than just one level
|
||||
// from the root variable.
|
||||
//
|
||||
// If the closures can handle such precison we should be able to mutate one path in the closure
|
||||
// while being able to mutate another path outside the closure, where the two paths are disjoint
|
||||
// after applying two projections on the root variable.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
#![allow(unused)]
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
struct Wrapper {
|
||||
p: Point,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
|
||||
|
||||
let mut c = || {
|
||||
w.p.x += 20;
|
||||
};
|
||||
|
||||
// `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`.
|
||||
let py = &mut w.p.y;
|
||||
c();
|
||||
|
||||
*py = 20
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/multilevel-path-1.rs:10:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
// run-pass
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
#![allow(unused)]
|
||||
|
||||
// If the closures can handle such precison we should be able to read one path in the closure
|
||||
// while being able mutate another path outside the closure, where the two paths are disjoint
|
||||
// after applying two projections on the root variable.
|
||||
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
struct Wrapper {
|
||||
p: Point,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
|
||||
|
||||
let c = || {
|
||||
println!("{}", w.p.x);
|
||||
};
|
||||
|
||||
// `c` only captures `w.p.x`, therefore it's safe to mutate `w.p.y`.
|
||||
let py = &mut w.p.y;
|
||||
c();
|
||||
|
||||
*py = 20
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/multilevel-path-2.rs:3:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
// run-pass
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
#![allow(unused)]
|
||||
|
||||
// Test that when `capture_disjoint_fields` is enabled we can read a path
|
||||
// both inside and outside the closure at the same time.
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
struct Wrapper {
|
||||
p: Point,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut w = Wrapper { p: Point { x: 10, y: 10 } };
|
||||
|
||||
let c = || {
|
||||
println!("{}", w.p.x);
|
||||
};
|
||||
|
||||
let px = &w.p.x;
|
||||
c();
|
||||
|
||||
println!("{}", px);
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/multilevel-path-3.rs:3:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// run-pass
|
||||
|
||||
// Test whether if we can do precise capture when using nested clsoure.
|
||||
|
||||
#![feature(capture_disjoint_fields)]
|
||||
//~^ WARNING: the feature `capture_disjoint_fields` is incomplete
|
||||
//~| NOTE: `#[warn(incomplete_features)]` on by default
|
||||
//~| NOTE: see issue #53488 <https://github.com/rust-lang/rust/issues/53488>
|
||||
|
||||
struct Point {
|
||||
x: i32,
|
||||
y: i32,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut p = Point { x: 5, y: 20 };
|
||||
|
||||
// c1 should capture `p.x` via immutable borrow and
|
||||
// `p.y` via mutable borrow.
|
||||
let mut c1 = || {
|
||||
println!("{}", p.x);
|
||||
|
||||
let incr = 10;
|
||||
|
||||
let mut c2 = || p.y += incr;
|
||||
c2();
|
||||
|
||||
println!("{}", p.y);
|
||||
};
|
||||
|
||||
c1();
|
||||
|
||||
// This should not throw an error because `p.x` is borrowed via Immutable borrow,
|
||||
// and multiple immutable borrow of the same place are allowed.
|
||||
let px = &p.x;
|
||||
|
||||
println!("{}", px);
|
||||
|
||||
c1();
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
warning: the feature `capture_disjoint_fields` is incomplete and may not be safe to use and/or cause compiler crashes
|
||||
--> $DIR/nested-closure.rs:5:12
|
||||
|
|
||||
LL | #![feature(capture_disjoint_fields)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
= note: see issue #53488 <https://github.com/rust-lang/rust/issues/53488> for more information
|
||||
|
||||
warning: 1 warning emitted
|
||||
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
fn main() {
|
||||
let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
|
||||
//~^ ERROR E0133
|
||||
let _: unsafe fn() = || unsafe { ::std::pin::Pin::new_unchecked(&0_u8); }; // OK
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
error[E0133]: call to unsafe function is unsafe and requires unsafe function or block
|
||||
--> $DIR/coerce-unsafe-closure-to-unsafe-fn-ptr.rs:2:31
|
||||
|
|
||||
LL | let _: unsafe fn() = || { ::std::pin::Pin::new_unchecked(&0_u8); };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ call to unsafe function
|
||||
|
|
||||
= note: consult the function's documentation for information on how to avoid undefined behavior
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0133`.
|
||||
4
src/test/ui/closures/coerce-unsafe-to-closure.rs
Normal file
4
src/test/ui/closures/coerce-unsafe-to-closure.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
fn main() {
|
||||
let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
|
||||
//~^ ERROR E0277
|
||||
}
|
||||
11
src/test/ui/closures/coerce-unsafe-to-closure.stderr
Normal file
11
src/test/ui/closures/coerce-unsafe-to-closure.stderr
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
error[E0277]: expected a `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
|
||||
--> $DIR/coerce-unsafe-to-closure.rs:2:44
|
||||
|
|
||||
LL | let x: Option<&[u8]> = Some("foo").map(std::mem::transmute);
|
||||
| ^^^^^^^^^^^^^^^^^^^ expected an `FnOnce<(&str,)>` closure, found `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
|
||||
|
|
||||
= help: the trait `FnOnce<(&str,)>` is not implemented for `unsafe extern "rust-intrinsic" fn(_) -> _ {transmute::<_, _>}`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0277`.
|
||||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
trait Trait {}
|
||||
|
||||
|
|
|
|||
23
src/test/ui/const-generics/arg-in-pat-1.rs
Normal file
23
src/test/ui/const-generics/arg-in-pat-1.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// check-pass
|
||||
enum ConstGenericEnum<const N: usize> {
|
||||
Foo([i32; N]),
|
||||
Bar,
|
||||
}
|
||||
|
||||
fn foo<const N: usize>(val: &ConstGenericEnum<N>) {
|
||||
if let ConstGenericEnum::<N>::Foo(field, ..) = val {}
|
||||
}
|
||||
|
||||
fn bar<const N: usize>(val: &ConstGenericEnum<N>) {
|
||||
match val {
|
||||
ConstGenericEnum::<N>::Foo(field, ..) => (),
|
||||
ConstGenericEnum::<N>::Bar => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match ConstGenericEnum::Bar {
|
||||
ConstGenericEnum::<3>::Foo(field, ..) => (),
|
||||
ConstGenericEnum::<3>::Bar => (),
|
||||
}
|
||||
}
|
||||
10
src/test/ui/const-generics/arg-in-pat-2.rs
Normal file
10
src/test/ui/const-generics/arg-in-pat-2.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// check-pass
|
||||
enum Generic<const N: usize> {
|
||||
Variant,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
match todo!() {
|
||||
Generic::<0usize>::Variant => todo!()
|
||||
}
|
||||
}
|
||||
43
src/test/ui/const-generics/arg-in-pat-3.rs
Normal file
43
src/test/ui/const-generics/arg-in-pat-3.rs
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
// check-pass
|
||||
struct Foo<const N: usize>;
|
||||
|
||||
fn bindingp() {
|
||||
match Foo {
|
||||
mut x @ Foo::<3> => {
|
||||
let ref mut _x @ Foo::<3> = x;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Bar<const N: usize> {
|
||||
field: Foo<N>,
|
||||
}
|
||||
|
||||
fn structp() {
|
||||
match todo!() {
|
||||
Bar::<3> {
|
||||
field: Foo::<3>,
|
||||
} => (),
|
||||
}
|
||||
}
|
||||
|
||||
struct Baz<const N: usize>(Foo<N>);
|
||||
|
||||
fn tuplestructp() {
|
||||
match Baz(Foo) {
|
||||
Baz::<3>(Foo::<3>) => (),
|
||||
}
|
||||
}
|
||||
|
||||
impl<const N: usize> Baz<N> {
|
||||
const ASSOC: usize = 3;
|
||||
}
|
||||
|
||||
fn pathp() {
|
||||
match 3 {
|
||||
Baz::<3>::ASSOC => (),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,11 +1,11 @@
|
|||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:12:32
|
||||
--> $DIR/argument_order.rs:11:32
|
||||
|
|
||||
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then consts and types: `<'a, 'b, const N: usize, T, const M: usize, U>`
|
||||
|
||||
error[E0747]: lifetime provided when a type was expected
|
||||
--> $DIR/argument_order.rs:20:23
|
||||
--> $DIR/argument_order.rs:19:23
|
||||
|
|
||||
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
|
||||
| ^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:6:28
|
||||
--> $DIR/argument_order.rs:5:28
|
||||
|
|
||||
LL | struct Bad<const N: usize, T> {
|
||||
| -----------------^- help: reorder the parameters: lifetimes, then types, then consts: `<T, const N: usize>`
|
||||
|
||||
error: lifetime parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:12:32
|
||||
--> $DIR/argument_order.rs:11:32
|
||||
|
|
||||
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
| -----------------^^-----^^-------------------- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
|
||||
|
||||
error: type parameters must be declared prior to const parameters
|
||||
--> $DIR/argument_order.rs:12:36
|
||||
--> $DIR/argument_order.rs:11:36
|
||||
|
|
||||
LL | struct AlsoBad<const N: usize, 'a, T, 'b, const M: usize, U> {
|
||||
| ---------------------^----------------------^- help: reorder the parameters: lifetimes, then types, then consts: `<'a, 'b, T, U, const N: usize, const M: usize>`
|
||||
|
||||
error[E0747]: lifetime provided when a type was expected
|
||||
--> $DIR/argument_order.rs:20:23
|
||||
--> $DIR/argument_order.rs:19:23
|
||||
|
|
||||
LL | let _: AlsoBad<7, 'static, u32, 'static, 17, u16>;
|
||||
| ^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
struct Bad<const N: usize, T> {
|
||||
//[min]~^ ERROR type parameters must be declared prior to const parameters
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:9:38
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:8:38
|
||||
|
|
||||
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -7,7 +7,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
|||
= note: this may fail depending on what value the parameter takes
|
||||
|
||||
error: constant expression depends on a generic parameter
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:20:10
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:19:10
|
||||
|
|
||||
LL | arr: [u8; CFG.arr_size],
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:9:48
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:8:48
|
||||
|
|
||||
LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
||||
| ^ cannot perform const operation using `N`
|
||||
|
|
@ -8,7 +8,7 @@ LL | struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
|||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: generic parameters may not be used in const operations
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:20:15
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:19:15
|
||||
|
|
||||
LL | arr: [u8; CFG.arr_size],
|
||||
| ^^^ cannot perform const operation using `CFG`
|
||||
|
|
@ -17,7 +17,7 @@ LL | arr: [u8; CFG.arr_size],
|
|||
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
|
||||
|
||||
error: `Config` is forbidden as the type of a const generic parameter
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:18:21
|
||||
--> $DIR/array-size-in-generic-struct-param.rs:17:21
|
||||
|
|
||||
LL | struct B<const CFG: Config> {
|
||||
| ^^^^^^
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct ArithArrayLen<const N: usize>([u32; 0 + N]);
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// revisions: full min
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
#![allow(dead_code)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
|
||||
--> $DIR/associated-type-bound-fail.rs:14:5
|
||||
--> $DIR/associated-type-bound-fail.rs:13:5
|
||||
|
|
||||
LL | type Assoc: Bar<N>;
|
||||
| ------ required by this bound in `Foo::Assoc`
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0277]: the trait bound `u16: Bar<N>` is not satisfied
|
||||
--> $DIR/associated-type-bound-fail.rs:14:5
|
||||
--> $DIR/associated-type-bound-fail.rs:13:5
|
||||
|
|
||||
LL | type Assoc: Bar<N>;
|
||||
| ------ required by this bound in `Foo::Assoc`
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// revisions: full min
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
trait Bar<const N: usize> {}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
// revisions: full min
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
trait Bar<const N: usize> {}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub struct Struct<const N: usize>(pub [u8; N]);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
// edition:2018
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub trait Foo<const N: usize> {}
|
||||
struct Local;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub struct Num<const N: usize>;
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#![cfg_attr(full, feature(const_generics))]
|
||||
#![cfg_attr(full, allow(incomplete_features))]
|
||||
#![cfg_attr(min, feature(min_const_generics))]
|
||||
|
||||
pub trait Foo {
|
||||
fn foo(&self);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue