From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ui/nll/user-annotations/adt-brace-enums.rs | 50 ++++++ .../ui/nll/user-annotations/adt-brace-enums.stderr | 42 +++++ .../ui/nll/user-annotations/adt-brace-structs.rs | 48 ++++++ .../nll/user-annotations/adt-brace-structs.stderr | 42 +++++ .../ui/nll/user-annotations/adt-nullary-enums.rs | 69 ++++++++ .../nll/user-annotations/adt-nullary-enums.stderr | 44 +++++ .../ui/nll/user-annotations/adt-tuple-enums.rs | 53 ++++++ .../ui/nll/user-annotations/adt-tuple-enums.stderr | 42 +++++ .../nll/user-annotations/adt-tuple-struct-calls.rs | 71 ++++++++ .../user-annotations/adt-tuple-struct-calls.stderr | 56 ++++++ .../ui/nll/user-annotations/adt-tuple-struct.rs | 48 ++++++ .../nll/user-annotations/adt-tuple-struct.stderr | 42 +++++ .../nll/user-annotations/cast_static_lifetime.rs | 6 + .../user-annotations/cast_static_lifetime.stderr | 14 ++ .../closure-substs.polonius.stderr | 61 +++++++ src/test/ui/nll/user-annotations/closure-substs.rs | 31 ++++ .../ui/nll/user-annotations/closure-substs.stderr | 42 +++++ .../constant-in-expr-inherent-1.rs | 12 ++ .../constant-in-expr-inherent-1.stderr | 10 ++ .../constant-in-expr-inherent-2.rs | 27 +++ .../constant-in-expr-inherent-2.stderr | 50 ++++++ .../user-annotations/constant-in-expr-normalize.rs | 22 +++ .../constant-in-expr-normalize.stderr | 10 ++ .../constant-in-expr-trait-item-1.rs | 14 ++ .../constant-in-expr-trait-item-1.stderr | 10 ++ .../constant-in-expr-trait-item-2.rs | 14 ++ .../constant-in-expr-trait-item-2.stderr | 10 ++ .../constant-in-expr-trait-item-3.rs | 14 ++ .../constant-in-expr-trait-item-3.stderr | 10 ++ src/test/ui/nll/user-annotations/downcast-infer.rs | 11 ++ .../nll/user-annotations/dump-adt-brace-struct.rs | 20 +++ .../user-annotations/dump-adt-brace-struct.stderr | 8 + src/test/ui/nll/user-annotations/dump-fn-method.rs | 57 +++++++ .../ui/nll/user-annotations/dump-fn-method.stderr | 26 +++ src/test/ui/nll/user-annotations/fns.rs | 48 ++++++ src/test/ui/nll/user-annotations/fns.stderr | 42 +++++ .../inherent-associated-constants.rs | 15 ++ .../inherent-associated-constants.stderr | 10 ++ src/test/ui/nll/user-annotations/issue-54124.rs | 8 + .../ui/nll/user-annotations/issue-54124.stderr | 20 +++ .../user-annotations/issue-54570-bootstrapping.rs | 30 ++++ src/test/ui/nll/user-annotations/issue-55219.rs | 18 ++ src/test/ui/nll/user-annotations/issue-55241.rs | 26 +++ .../issue-55748-pat-types-constrain-bindings.rs | 68 ++++++++ ...issue-55748-pat-types-constrain-bindings.stderr | 29 ++++ .../issue-57731-ascibed-coupled-types.rs | 40 +++++ .../issue-57731-ascibed-coupled-types.stderr | 38 +++++ src/test/ui/nll/user-annotations/method-call.rs | 69 ++++++++ .../ui/nll/user-annotations/method-call.stderr | 43 +++++ src/test/ui/nll/user-annotations/method-ufcs-1.rs | 63 +++++++ .../ui/nll/user-annotations/method-ufcs-1.stderr | 46 +++++ src/test/ui/nll/user-annotations/method-ufcs-2.rs | 63 +++++++ .../ui/nll/user-annotations/method-ufcs-2.stderr | 46 +++++ src/test/ui/nll/user-annotations/method-ufcs-3.rs | 69 ++++++++ .../ui/nll/user-annotations/method-ufcs-3.stderr | 43 +++++ .../nll/user-annotations/method-ufcs-inherent-1.rs | 18 ++ .../user-annotations/method-ufcs-inherent-1.stderr | 18 ++ .../nll/user-annotations/method-ufcs-inherent-2.rs | 19 +++ .../user-annotations/method-ufcs-inherent-2.stderr | 33 ++++ .../nll/user-annotations/method-ufcs-inherent-3.rs | 18 ++ .../user-annotations/method-ufcs-inherent-3.stderr | 18 ++ .../nll/user-annotations/method-ufcs-inherent-4.rs | 20 +++ .../user-annotations/method-ufcs-inherent-4.stderr | 33 ++++ src/test/ui/nll/user-annotations/normalization.rs | 10 ++ .../ui/nll/user-annotations/normalization.stderr | 13 ++ .../ui/nll/user-annotations/normalize-self-ty.rs | 23 +++ .../pattern_substs_on_brace_enum_variant.rs | 22 +++ .../pattern_substs_on_brace_enum_variant.stderr | 26 +++ .../pattern_substs_on_brace_struct.rs | 20 +++ .../pattern_substs_on_brace_struct.stderr | 26 +++ .../pattern_substs_on_tuple_enum_variant.rs | 22 +++ .../pattern_substs_on_tuple_enum_variant.stderr | 26 +++ .../pattern_substs_on_tuple_struct.rs | 20 +++ .../pattern_substs_on_tuple_struct.stderr | 26 +++ src/test/ui/nll/user-annotations/patterns.rs | 136 +++++++++++++++ src/test/ui/nll/user-annotations/patterns.stderr | 189 +++++++++++++++++++++ .../ui/nll/user-annotations/promoted-annotation.rs | 10 ++ .../user-annotations/promoted-annotation.stderr | 17 ++ .../user-annotations/type-annotation-with-hrtb.rs | 33 ++++ .../type_ascription_static_lifetime.rs | 7 + .../type_ascription_static_lifetime.stderr | 14 ++ src/test/ui/nll/user-annotations/wf-self-type.rs | 13 ++ .../ui/nll/user-annotations/wf-self-type.stderr | 14 ++ 83 files changed, 2764 insertions(+) create mode 100644 src/test/ui/nll/user-annotations/adt-brace-enums.rs create mode 100644 src/test/ui/nll/user-annotations/adt-brace-enums.stderr create mode 100644 src/test/ui/nll/user-annotations/adt-brace-structs.rs create mode 100644 src/test/ui/nll/user-annotations/adt-brace-structs.stderr create mode 100644 src/test/ui/nll/user-annotations/adt-nullary-enums.rs create mode 100644 src/test/ui/nll/user-annotations/adt-nullary-enums.stderr create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-enums.rs create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-enums.stderr create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-struct-calls.rs create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-struct.rs create mode 100644 src/test/ui/nll/user-annotations/adt-tuple-struct.stderr create mode 100644 src/test/ui/nll/user-annotations/cast_static_lifetime.rs create mode 100644 src/test/ui/nll/user-annotations/cast_static_lifetime.stderr create mode 100644 src/test/ui/nll/user-annotations/closure-substs.polonius.stderr create mode 100644 src/test/ui/nll/user-annotations/closure-substs.rs create mode 100644 src/test/ui/nll/user-annotations/closure-substs.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs create mode 100644 src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr create mode 100644 src/test/ui/nll/user-annotations/downcast-infer.rs create mode 100644 src/test/ui/nll/user-annotations/dump-adt-brace-struct.rs create mode 100644 src/test/ui/nll/user-annotations/dump-adt-brace-struct.stderr create mode 100644 src/test/ui/nll/user-annotations/dump-fn-method.rs create mode 100644 src/test/ui/nll/user-annotations/dump-fn-method.stderr create mode 100644 src/test/ui/nll/user-annotations/fns.rs create mode 100644 src/test/ui/nll/user-annotations/fns.stderr create mode 100644 src/test/ui/nll/user-annotations/inherent-associated-constants.rs create mode 100644 src/test/ui/nll/user-annotations/inherent-associated-constants.stderr create mode 100644 src/test/ui/nll/user-annotations/issue-54124.rs create mode 100644 src/test/ui/nll/user-annotations/issue-54124.stderr create mode 100644 src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55219.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55241.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs create mode 100644 src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr create mode 100644 src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs create mode 100644 src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.stderr create mode 100644 src/test/ui/nll/user-annotations/method-call.rs create mode 100644 src/test/ui/nll/user-annotations/method-call.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-1.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-1.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-2.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-2.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-3.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-3.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-1.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-2.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-3.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-4.rs create mode 100644 src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr create mode 100644 src/test/ui/nll/user-annotations/normalization.rs create mode 100644 src/test/ui/nll/user-annotations/normalization.stderr create mode 100644 src/test/ui/nll/user-annotations/normalize-self-ty.rs create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.rs create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.rs create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.rs create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.rs create mode 100644 src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr create mode 100644 src/test/ui/nll/user-annotations/patterns.rs create mode 100644 src/test/ui/nll/user-annotations/patterns.stderr create mode 100644 src/test/ui/nll/user-annotations/promoted-annotation.rs create mode 100644 src/test/ui/nll/user-annotations/promoted-annotation.stderr create mode 100644 src/test/ui/nll/user-annotations/type-annotation-with-hrtb.rs create mode 100644 src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs create mode 100644 src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr create mode 100644 src/test/ui/nll/user-annotations/wf-self-type.rs create mode 100644 src/test/ui/nll/user-annotations/wf-self-type.stderr (limited to 'src/test/ui/nll/user-annotations') diff --git a/src/test/ui/nll/user-annotations/adt-brace-enums.rs b/src/test/ui/nll/user-annotations/adt-brace-enums.rs new file mode 100644 index 000000000..0d9828342 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-brace-enums.rs @@ -0,0 +1,50 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +enum SomeEnum { + SomeVariant { t: T } +} + +fn no_annot() { + let c = 66; + SomeEnum::SomeVariant { t: &c }; +} + +fn annot_underscore() { + let c = 66; + SomeEnum::SomeVariant::<_> { t: &c }; +} + +fn annot_reference_any_lifetime() { + let c = 66; + SomeEnum::SomeVariant::<&u32> { t: &c }; +} + +fn annot_reference_static_lifetime() { + let c = 66; + SomeEnum::SomeVariant::<&'static u32> { t: &c }; //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + SomeEnum::SomeVariant::<&'a u32> { t: &c }; //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + SomeEnum::SomeVariant::<&'a u32> { t: c }; +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + SomeEnum::SomeVariant::<&'a u32> { t: &c }; //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + SomeEnum::SomeVariant::<&'a u32> { t: c }; + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-brace-enums.stderr b/src/test/ui/nll/user-annotations/adt-brace-enums.stderr new file mode 100644 index 000000000..253e38251 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-brace-enums.stderr @@ -0,0 +1,42 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-enums.rs:25:48 + | +LL | SomeEnum::SomeVariant::<&'static u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-enums.rs:30:43 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +LL | let c = 66; +LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-enums.rs:40:47 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | SomeEnum::SomeVariant::<&'a u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | }; + | - `c` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/adt-brace-structs.rs b/src/test/ui/nll/user-annotations/adt-brace-structs.rs new file mode 100644 index 000000000..bdbfd87d5 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-brace-structs.rs @@ -0,0 +1,48 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +struct SomeStruct { t: T } + +fn no_annot() { + let c = 66; + SomeStruct { t: &c }; +} + +fn annot_underscore() { + let c = 66; + SomeStruct::<_> { t: &c }; +} + +fn annot_reference_any_lifetime() { + let c = 66; + SomeStruct::<&u32> { t: &c }; +} + +fn annot_reference_static_lifetime() { + let c = 66; + SomeStruct::<&'static u32> { t: &c }; //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + SomeStruct::<&'a u32> { t: &c }; //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + SomeStruct::<&'a u32> { t: c }; +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + SomeStruct::<&'a u32> { t: &c }; //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + SomeStruct::<&'a u32> { t: c }; + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-brace-structs.stderr b/src/test/ui/nll/user-annotations/adt-brace-structs.stderr new file mode 100644 index 000000000..8b9d1705d --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-brace-structs.stderr @@ -0,0 +1,42 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-structs.rs:23:37 + | +LL | SomeStruct::<&'static u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-structs.rs:28:32 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +LL | let c = 66; +LL | SomeStruct::<&'a u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-brace-structs.rs:38:36 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | SomeStruct::<&'a u32> { t: &c }; + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | }; + | - `c` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/adt-nullary-enums.rs b/src/test/ui/nll/user-annotations/adt-nullary-enums.rs new file mode 100644 index 000000000..53853668d --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-nullary-enums.rs @@ -0,0 +1,69 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +#![allow(warnings)] + +use std::cell::Cell; + +enum SomeEnum { + SomeVariant(T), + SomeOtherVariant, +} + +fn combine(_: T, _: T) { } + +fn no_annot() { + let c = 66; + combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant); +} + +fn annot_underscore() { + let c = 66; + combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant::>); +} + +fn annot_reference_any_lifetime() { + let c = 66; + combine(SomeEnum::SomeVariant(Cell::new(&c)), SomeEnum::SomeOtherVariant::>); +} + +fn annot_reference_static_lifetime() { + let c = 66; + combine( + SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR + SomeEnum::SomeOtherVariant::>, + ); +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + combine( + SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR + SomeEnum::SomeOtherVariant::>, + ); +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + combine(SomeEnum::SomeVariant(Cell::new(c)), SomeEnum::SomeOtherVariant::>); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + combine( + SomeEnum::SomeVariant(Cell::new(&c)), //~ ERROR + SomeEnum::SomeOtherVariant::>, + ); + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + combine( + SomeEnum::SomeVariant(Cell::new(c)), + SomeEnum::SomeOtherVariant::>, + ); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr new file mode 100644 index 000000000..ee332278c --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-nullary-enums.stderr @@ -0,0 +1,44 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-nullary-enums.rs:33:41 + | +LL | / combine( +LL | | SomeEnum::SomeVariant(Cell::new(&c)), + | | ^^ borrowed value does not live long enough +LL | | SomeEnum::SomeOtherVariant::>, +LL | | ); + | |_____- argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-nullary-enums.rs:41:41 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | SomeEnum::SomeVariant(Cell::new(&c)), + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` +... +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-nullary-enums.rs:54:45 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +LL | let _closure = || { + | - `c` dropped here while still borrowed +... +LL | SomeEnum::SomeVariant(Cell::new(&c)), + | ----------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/adt-tuple-enums.rs b/src/test/ui/nll/user-annotations/adt-tuple-enums.rs new file mode 100644 index 000000000..efe8dfda1 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-enums.rs @@ -0,0 +1,53 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +#![allow(warnings)] + +enum SomeEnum { + SomeVariant(T), + SomeOtherVariant, +} + +fn no_annot() { + let c = 66; + SomeEnum::SomeVariant(&c); +} + +fn annot_underscore() { + let c = 66; + SomeEnum::SomeVariant::<_>(&c); +} + +fn annot_reference_any_lifetime() { + let c = 66; + SomeEnum::SomeVariant::<&u32>(&c); +} + +fn annot_reference_static_lifetime() { + let c = 66; + SomeEnum::SomeVariant::<&'static u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + SomeEnum::SomeVariant::<&'a u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + SomeEnum::SomeVariant::<&'a u32>(c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + SomeEnum::SomeVariant::<&'a u32>(&c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + SomeEnum::SomeVariant::<&'a u32>(c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr b/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr new file mode 100644 index 000000000..2fa704263 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-enums.stderr @@ -0,0 +1,42 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-enums.rs:28:43 + | +LL | SomeEnum::SomeVariant::<&'static u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-enums.rs:33:38 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +LL | let c = 66; +LL | SomeEnum::SomeVariant::<&'a u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-enums.rs:43:42 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | SomeEnum::SomeVariant::<&'a u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | }; + | - `c` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.rs b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.rs new file mode 100644 index 000000000..116583223 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.rs @@ -0,0 +1,71 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +struct SomeStruct(T); + +fn no_annot() { + let c = 66; + let f = SomeStruct; + f(&c); +} + +fn annot_underscore() { + let c = 66; + let f = SomeStruct::<_>; + f(&c); +} + +fn annot_reference_any_lifetime() { + let c = 66; + let f = SomeStruct::<&u32>; + f(&c); +} + +fn annot_reference_static_lifetime() { + let c = 66; + let f = SomeStruct::<&'static u32>; + f(&c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + let f = SomeStruct::<&'a u32>; + f(&c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + let f = SomeStruct::<&'a u32>; + f(c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + let f = SomeStruct::<&'a u32>; + f(&c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_across_closure<'a>(_: &'a u32) { + let f = SomeStruct::<&'a u32>; + let _closure = || { + let c = 66; + f(&c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + let f = SomeStruct::<&'a u32>; + f(c); + }; +} + +fn annot_reference_named_lifetime_across_closure_ok<'a>(c: &'a u32) { + let f = SomeStruct::<&'a u32>; + let _closure = || { + f(c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr new file mode 100644 index 000000000..95bbd62c4 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct-calls.stderr @@ -0,0 +1,56 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct-calls.rs:27:7 + | +LL | f(&c); + | --^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct-calls.rs:33:7 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | f(&c); + | --^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct-calls.rs:45:11 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +LL | let _closure = || { + | - `c` dropped here while still borrowed +... +LL | f(&c); + | --^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct-calls.rs:53:11 + | +LL | let f = SomeStruct::<&'a u32>; + | - lifetime `'1` appears in the type of `f` +LL | let _closure = || { + | - `c` dropped here while still borrowed +LL | let c = 66; +LL | f(&c); + | --^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'1` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct.rs b/src/test/ui/nll/user-annotations/adt-tuple-struct.rs new file mode 100644 index 000000000..37284e1fd --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct.rs @@ -0,0 +1,48 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +struct SomeStruct(T); + +fn no_annot() { + let c = 66; + SomeStruct(&c); +} + +fn annot_underscore() { + let c = 66; + SomeStruct::<_>(&c); +} + +fn annot_reference_any_lifetime() { + let c = 66; + SomeStruct::<&u32>(&c); +} + +fn annot_reference_static_lifetime() { + let c = 66; + SomeStruct::<&'static u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + SomeStruct::<&'a u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + SomeStruct::<&'a u32>(c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + SomeStruct::<&'a u32>(&c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + SomeStruct::<&'a u32>(c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr b/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr new file mode 100644 index 000000000..76b525225 --- /dev/null +++ b/src/test/ui/nll/user-annotations/adt-tuple-struct.stderr @@ -0,0 +1,42 @@ +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct.rs:23:32 + | +LL | SomeStruct::<&'static u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct.rs:28:27 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +LL | let c = 66; +LL | SomeStruct::<&'a u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/adt-tuple-struct.rs:38:31 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | SomeStruct::<&'a u32>(&c); + | ^^ + | | + | borrowed value does not live long enough + | this usage requires that `c` is borrowed for `'a` +LL | }; + | - `c` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/cast_static_lifetime.rs b/src/test/ui/nll/user-annotations/cast_static_lifetime.rs new file mode 100644 index 000000000..bb6129dac --- /dev/null +++ b/src/test/ui/nll/user-annotations/cast_static_lifetime.rs @@ -0,0 +1,6 @@ +#![allow(warnings)] + +fn main() { + let x = 22_u32; + let y: &u32 = (&x) as &'static u32; //~ ERROR `x` does not live long enough +} diff --git a/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr b/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr new file mode 100644 index 000000000..4599d04e7 --- /dev/null +++ b/src/test/ui/nll/user-annotations/cast_static_lifetime.stderr @@ -0,0 +1,14 @@ +error[E0597]: `x` does not live long enough + --> $DIR/cast_static_lifetime.rs:5:19 + | +LL | let y: &u32 = (&x) as &'static u32; + | ^^^^---------------- + | | + | borrowed value does not live long enough + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/closure-substs.polonius.stderr b/src/test/ui/nll/user-annotations/closure-substs.polonius.stderr new file mode 100644 index 000000000..af159a6cd --- /dev/null +++ b/src/test/ui/nll/user-annotations/closure-substs.polonius.stderr @@ -0,0 +1,61 @@ +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:8:16 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +... +LL | return x; + | ^ returning this value requires that `'a` must outlive `'static` + | + = help: consider replacing `'a` with `'static` + +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:15:16 + | +LL | |x: &i32| -> &'static i32 { + | - let's call the lifetime of this reference `'1` +LL | return x; + | ^ returning this value requires that `'1` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:15:16 + | +LL | |x: &i32| -> &'static i32 { + | - - let's call the lifetime of this reference `'2` + | | + | let's call the lifetime of this reference `'1` +LL | return x; + | ^ returning this value requires that `'1` must outlive `'2` + +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:22:9 + | +LL | fn bar<'a>() { + | -- lifetime `'a` defined here +... +LL | b(x); + | ^^^^ argument requires that `'a` must outlive `'static` + | + = help: consider replacing `'a` with `'static` + +error[E0521]: borrowed data escapes outside of closure + --> $DIR/closure-substs.rs:29:9 + | +LL | |x: &i32, b: fn(&'static i32)| { + | - `x` is a reference that is only valid in the closure body +LL | b(x); + | ^^^^ `x` escapes the closure body here + +error[E0521]: borrowed data escapes outside of closure + --> $DIR/closure-substs.rs:29:9 + | +LL | |x: &i32, b: fn(&'static i32)| { + | - - `b` declared here, outside of the closure body + | | + | `x` is a reference that is only valid in the closure body +LL | b(x); + | ^^^^ `x` escapes the closure body here + +error: aborting due to 6 previous errors + +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/user-annotations/closure-substs.rs b/src/test/ui/nll/user-annotations/closure-substs.rs new file mode 100644 index 000000000..f7af54e8d --- /dev/null +++ b/src/test/ui/nll/user-annotations/closure-substs.rs @@ -0,0 +1,31 @@ +// Test that we enforce user-provided type annotations on closures. + +fn foo<'a>() { + // Here `x` is free in the closure sig: + |x: &'a i32| -> &'static i32 { + return x; //~ ERROR lifetime may not live long enough + }; +} + +fn foo1() { + // Here `x` is bound in the closure sig: + |x: &i32| -> &'static i32 { + return x; //~ ERROR lifetime may not live long enough + }; +} + +fn bar<'a>() { + // Here `x` is free in the closure sig: + |x: &'a i32, b: fn(&'static i32)| { + b(x); //~ ERROR lifetime may not live long enough + }; +} + +fn bar1() { + // Here `x` is bound in the closure sig: + |x: &i32, b: fn(&'static i32)| { + b(x); //~ ERROR borrowed data escapes outside of closure + }; +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/closure-substs.stderr b/src/test/ui/nll/user-annotations/closure-substs.stderr new file mode 100644 index 000000000..1e8de4ba9 --- /dev/null +++ b/src/test/ui/nll/user-annotations/closure-substs.stderr @@ -0,0 +1,42 @@ +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:6:16 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +... +LL | return x; + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:13:16 + | +LL | |x: &i32| -> &'static i32 { + | - let's call the lifetime of this reference `'1` +LL | return x; + | ^ returning this value requires that `'1` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/closure-substs.rs:20:9 + | +LL | fn bar<'a>() { + | -- lifetime `'a` defined here +... +LL | b(x); + | ^^^^ argument requires that `'a` must outlive `'static` + +error[E0521]: borrowed data escapes outside of closure + --> $DIR/closure-substs.rs:27:9 + | +LL | |x: &i32, b: fn(&'static i32)| { + | - - let's call the lifetime of this reference `'1` + | | + | `x` is a reference that is only valid in the closure body +LL | b(x); + | ^^^^ + | | + | `x` escapes the closure body here + | argument requires that `'1` must outlive `'static` + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0521`. diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs new file mode 100644 index 000000000..e3a8a5f58 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.rs @@ -0,0 +1,12 @@ +struct Foo<'a> { x: &'a u32 } + +impl<'a> Foo<'a> { + const C: &'a u32 = &22; +} + +fn foo<'a>(_: &'a u32) -> &'static u32 { + >::C //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr new file mode 100644 index 000000000..c39301588 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-1.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/constant-in-expr-inherent-1.rs:8:5 + | +LL | fn foo<'a>(_: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | >::C + | ^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.rs b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.rs new file mode 100644 index 000000000..90696d4b1 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.rs @@ -0,0 +1,27 @@ +// Test that we still check constants are well-formed, even when we there's no +// type annotation to check. + +const FUN: fn(&'static ()) = |_| {}; +struct A; +impl A { + const ASSOCIATED_FUN: fn(&'static ()) = |_| {}; +} + +struct B<'a>(&'a ()); +impl B<'static> { + const ALSO_ASSOCIATED_FUN: fn(&'static ()) = |_| {}; +} + +trait Z: 'static { + const TRAIT_ASSOCIATED_FUN: fn(&'static Self) = |_| (); +} + +impl Z for () {} + +fn main() { + let x = (); + FUN(&x); //~ ERROR `x` does not live long enough + A::ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough + B::ALSO_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough + <_>::TRAIT_ASSOCIATED_FUN(&x); //~ ERROR `x` does not live long enough +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.stderr new file mode 100644 index 000000000..12065a85a --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-inherent-2.stderr @@ -0,0 +1,50 @@ +error[E0597]: `x` does not live long enough + --> $DIR/constant-in-expr-inherent-2.rs:23:9 + | +LL | FUN(&x); + | ----^^- + | | | + | | borrowed value does not live long enough + | argument requires that `x` is borrowed for `'static` +... +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/constant-in-expr-inherent-2.rs:24:23 + | +LL | A::ASSOCIATED_FUN(&x); + | ------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `x` is borrowed for `'static` +... +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/constant-in-expr-inherent-2.rs:25:28 + | +LL | B::ALSO_ASSOCIATED_FUN(&x); + | -----------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `x` is borrowed for `'static` +LL | <_>::TRAIT_ASSOCIATED_FUN(&x); +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/constant-in-expr-inherent-2.rs:26:31 + | +LL | <_>::TRAIT_ASSOCIATED_FUN(&x); + | --------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error: aborting due to 4 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs new file mode 100644 index 000000000..b7095430d --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.rs @@ -0,0 +1,22 @@ +trait Mirror { + type Me; +} + +impl Mirror for T { + type Me = T; +} + +trait Foo<'a> { + const C: <&'a u32 as Mirror>::Me; +} + +impl<'a, T> Foo<'a> for T { + const C: &'a u32 = &22; +} + +fn foo<'a>(_: &'a u32) -> &'static u32 { + <() as Foo<'a>>::C //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr new file mode 100644 index 000000000..541a2cfaf --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-normalize.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/constant-in-expr-normalize.rs:18:5 + | +LL | fn foo<'a>(_: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | <() as Foo<'a>>::C + | ^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs new file mode 100644 index 000000000..e0400b2cc --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.rs @@ -0,0 +1,14 @@ +trait Foo<'a> { + const C: &'a u32; +} + +impl<'a, T> Foo<'a> for T { + const C: &'a u32 = &22; +} + +fn foo<'a>(_: &'a u32) -> &'static u32 { + <() as Foo<'a>>::C //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr new file mode 100644 index 000000000..ea0fcb6d6 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-1.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/constant-in-expr-trait-item-1.rs:10:5 + | +LL | fn foo<'a>(_: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | <() as Foo<'a>>::C + | ^^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs new file mode 100644 index 000000000..73c4e577b --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.rs @@ -0,0 +1,14 @@ +trait Foo<'a> { + const C: &'a u32; +} + +impl<'a, T> Foo<'a> for T { + const C: &'a u32 = &22; +} + +fn foo<'a, T: Foo<'a>>() -> &'static u32 { + >::C //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr new file mode 100644 index 000000000..ff549f1d8 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-2.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/constant-in-expr-trait-item-2.rs:10:5 + | +LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { + | -- lifetime `'a` defined here +LL | >::C + | ^^^^^^^^^^^^^^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs new file mode 100644 index 000000000..567e31ef9 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.rs @@ -0,0 +1,14 @@ +trait Foo<'a> { + const C: &'a u32; +} + +impl<'a, T> Foo<'a> for T { + const C: &'a u32 = &22; +} + +fn foo<'a, T: Foo<'a>>() -> &'static u32 { + T::C //~ ERROR +} + +fn main() { +} diff --git a/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr new file mode 100644 index 000000000..7f160d8e3 --- /dev/null +++ b/src/test/ui/nll/user-annotations/constant-in-expr-trait-item-3.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/constant-in-expr-trait-item-3.rs:10:5 + | +LL | fn foo<'a, T: Foo<'a>>() -> &'static u32 { + | -- lifetime `'a` defined here +LL | T::C + | ^^^^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/downcast-infer.rs b/src/test/ui/nll/user-annotations/downcast-infer.rs new file mode 100644 index 000000000..b27429f4d --- /dev/null +++ b/src/test/ui/nll/user-annotations/downcast-infer.rs @@ -0,0 +1,11 @@ +// check-pass + +// Check that we don't try to downcast `_` when type-checking the annotation. +fn main() { + let x = Some(Some(Some(1))); + + match x { + Some::>(Some(Some(v))) => (), + _ => (), + } +} diff --git a/src/test/ui/nll/user-annotations/dump-adt-brace-struct.rs b/src/test/ui/nll/user-annotations/dump-adt-brace-struct.rs new file mode 100644 index 000000000..ccda9129d --- /dev/null +++ b/src/test/ui/nll/user-annotations/dump-adt-brace-struct.rs @@ -0,0 +1,20 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +// compile-flags:-Zverbose + +#![allow(warnings)] +#![feature(rustc_attrs)] + +struct SomeStruct { t: T } + +#[rustc_dump_user_substs] +fn main() { + SomeStruct { t: 22 }; // Nothing given, no annotation. + + SomeStruct::<_> { t: 22 }; // Nothing interesting given, no annotation. + + SomeStruct:: { t: 22 }; // No lifetime bounds given. + + SomeStruct::<&'static u32> { t: &22 }; //~ ERROR [&ReStatic u32] +} diff --git a/src/test/ui/nll/user-annotations/dump-adt-brace-struct.stderr b/src/test/ui/nll/user-annotations/dump-adt-brace-struct.stderr new file mode 100644 index 000000000..586062190 --- /dev/null +++ b/src/test/ui/nll/user-annotations/dump-adt-brace-struct.stderr @@ -0,0 +1,8 @@ +error: user substs: UserSubsts { substs: [&ReStatic u32], user_self_ty: None } + --> $DIR/dump-adt-brace-struct.rs:19:5 + | +LL | SomeStruct::<&'static u32> { t: &22 }; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/dump-fn-method.rs b/src/test/ui/nll/user-annotations/dump-fn-method.rs new file mode 100644 index 000000000..148d63d84 --- /dev/null +++ b/src/test/ui/nll/user-annotations/dump-fn-method.rs @@ -0,0 +1,57 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +// compile-flags:-Zverbose + +#![feature(rustc_attrs)] + +// Note: we reference the names T and U in the comments below. +trait Bazoom { + fn method(&self, arg: T, arg2: U) { } +} + +impl Bazoom for S { +} + +fn foo<'a, T>(_: T) { } + +#[rustc_dump_user_substs] +fn main() { + // Here: nothing is given, so we don't have any annotation. + let x = foo; + x(22); + + // Here: `u32` is given, which doesn't contain any lifetimes, so we don't + // have any annotation. + let x = foo::; + x(22); + + let x = foo::<&'static u32>; //~ ERROR [&ReStatic u32] + x(&22); + + // Here: we only want the `T` to be given, the rest should be variables. + // + // (`T` refers to the declaration of `Bazoom`) + let x = <_ as Bazoom>::method::<_>; //~ ERROR [^0, u32, ^1] + x(&22, 44, 66); + + // Here: all are given and definitely contain no lifetimes, so we + // don't have any annotation. + let x = >::method::; + x(&22, 44, 66); + + // Here: all are given and we have a lifetime. + let x = >::method::; //~ ERROR [u8, &ReStatic u16, u32] + x(&22, &44, 66); + + // Here: we want in particular that *only* the method `U` + // annotation is given, the rest are variables. + // + // (`U` refers to the declaration of `Bazoom`) + let y = 22_u32; + y.method::(44, 66); //~ ERROR [^0, ^1, u32] + + // Here: nothing is given, so we don't have any annotation. + let y = 22_u32; + y.method(44, 66); +} diff --git a/src/test/ui/nll/user-annotations/dump-fn-method.stderr b/src/test/ui/nll/user-annotations/dump-fn-method.stderr new file mode 100644 index 000000000..d139efa88 --- /dev/null +++ b/src/test/ui/nll/user-annotations/dump-fn-method.stderr @@ -0,0 +1,26 @@ +error: user substs: UserSubsts { substs: [&ReStatic u32], user_self_ty: None } + --> $DIR/dump-fn-method.rs:29:13 + | +LL | let x = foo::<&'static u32>; + | ^^^^^^^^^^^^^^^^^^^ + +error: user substs: UserSubsts { substs: [^0, u32, ^1], user_self_ty: None } + --> $DIR/dump-fn-method.rs:35:13 + | +LL | let x = <_ as Bazoom>::method::<_>; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: user substs: UserSubsts { substs: [u8, &ReStatic u16, u32], user_self_ty: None } + --> $DIR/dump-fn-method.rs:44:13 + | +LL | let x = >::method::; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: user substs: UserSubsts { substs: [^0, ^1, u32], user_self_ty: None } + --> $DIR/dump-fn-method.rs:52:5 + | +LL | y.method::(44, 66); + | ^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/nll/user-annotations/fns.rs b/src/test/ui/nll/user-annotations/fns.rs new file mode 100644 index 000000000..38db6d1c4 --- /dev/null +++ b/src/test/ui/nll/user-annotations/fns.rs @@ -0,0 +1,48 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +fn some_fn(arg: T) { } + +fn no_annot() { + let c = 66; + some_fn(&c); // OK +} + +fn annot_underscore() { + let c = 66; + some_fn::<_>(&c); // OK +} + +fn annot_reference_any_lifetime() { + let c = 66; + some_fn::<&u32>(&c); // OK +} + +fn annot_reference_static_lifetime() { + let c = 66; + some_fn::<&'static u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let c = 66; + some_fn::<&'a u32>(&c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + some_fn::<&'a u32>(c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let _closure = || { + let c = 66; + some_fn::<&'a u32>(&c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let _closure = || { + some_fn::<&'a u32>(c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/fns.stderr b/src/test/ui/nll/user-annotations/fns.stderr new file mode 100644 index 000000000..bd4d121d5 --- /dev/null +++ b/src/test/ui/nll/user-annotations/fns.stderr @@ -0,0 +1,42 @@ +error[E0597]: `c` does not live long enough + --> $DIR/fns.rs:23:29 + | +LL | some_fn::<&'static u32>(&c); + | ------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/fns.rs:28:24 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +LL | let c = 66; +LL | some_fn::<&'a u32>(&c); + | -------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/fns.rs:38:28 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +LL | let _closure = || { + | - `c` dropped here while still borrowed +LL | let c = 66; +LL | some_fn::<&'a u32>(&c); + | -------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/inherent-associated-constants.rs b/src/test/ui/nll/user-annotations/inherent-associated-constants.rs new file mode 100644 index 000000000..fe2641fd6 --- /dev/null +++ b/src/test/ui/nll/user-annotations/inherent-associated-constants.rs @@ -0,0 +1,15 @@ +struct A<'a>(&'a ()); + +impl A<'static> { + const IC: i32 = 10; +} + +fn non_wf_associated_const<'a>(x: i32) { + A::<'a>::IC; //~ ERROR lifetime may not live long enough +} + +fn wf_associated_const<'a>(x: i32) { + A::<'static>::IC; +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr b/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr new file mode 100644 index 000000000..ffbfc40f5 --- /dev/null +++ b/src/test/ui/nll/user-annotations/inherent-associated-constants.stderr @@ -0,0 +1,10 @@ +error: lifetime may not live long enough + --> $DIR/inherent-associated-constants.rs:8:5 + | +LL | fn non_wf_associated_const<'a>(x: i32) { + | -- lifetime `'a` defined here +LL | A::<'a>::IC; + | ^^^^^^^^^^^ requires that `'a` must outlive `'static` + +error: aborting due to previous error + diff --git a/src/test/ui/nll/user-annotations/issue-54124.rs b/src/test/ui/nll/user-annotations/issue-54124.rs new file mode 100644 index 000000000..5ae03c894 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-54124.rs @@ -0,0 +1,8 @@ +fn test<'a>() { + let _:fn(&()) = |_:&'a ()| {}; //~ ERROR lifetime may not live long enough + //~^ ERROR lifetime may not live long enough +} + +fn main() { + test(); +} diff --git a/src/test/ui/nll/user-annotations/issue-54124.stderr b/src/test/ui/nll/user-annotations/issue-54124.stderr new file mode 100644 index 000000000..2556af2dd --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-54124.stderr @@ -0,0 +1,20 @@ +error: lifetime may not live long enough + --> $DIR/issue-54124.rs:2:22 + | +LL | fn test<'a>() { + | -- lifetime `'a` defined here +LL | let _:fn(&()) = |_:&'a ()| {}; + | ^ - let's call the lifetime of this reference `'1` + | | + | requires that `'1` must outlive `'a` + +error: lifetime may not live long enough + --> $DIR/issue-54124.rs:2:22 + | +LL | fn test<'a>() { + | -- lifetime `'a` defined here +LL | let _:fn(&()) = |_:&'a ()| {}; + | ^ requires that `'a` must outlive `'static` + +error: aborting due to 2 previous errors + diff --git a/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs b/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs new file mode 100644 index 000000000..ff5b2244e --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-54570-bootstrapping.rs @@ -0,0 +1,30 @@ +// check-pass + +// This test is reduced from a scenario pnkfelix encountered while +// bootstrapping the compiler. + +#[derive(Copy, Clone)] +pub struct Spanned { + pub node: T, + pub span: Span, +} + +pub type Variant = Spanned; +// #[derive(Clone)] pub struct Variant { pub node: VariantKind, pub span: Span, } + +#[derive(Clone)] +pub struct VariantKind { } + +#[derive(Copy, Clone)] +pub struct Span; + +pub fn variant_to_span(variant: Variant) { + match variant { + Variant { + span: _span, + .. + } => { } + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/issue-55219.rs b/src/test/ui/nll/user-annotations/issue-55219.rs new file mode 100644 index 000000000..147413663 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55219.rs @@ -0,0 +1,18 @@ +// Regression test for #55219: +// +// The `Self::HASH_LEN` here expands to a "self-type" where `T` is not +// known. This unbound inference variable was causing an ICE. +// +// check-pass + +pub struct Foo(T); + +impl Foo { + const HASH_LEN: usize = 20; + + fn stuff() { + let _ = Self::HASH_LEN; + } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/issue-55241.rs b/src/test/ui/nll/user-annotations/issue-55241.rs new file mode 100644 index 000000000..29969c7b4 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55241.rs @@ -0,0 +1,26 @@ +// Regression test for #55241: +// +// The reference to `C::HASHED_NULL_NODE` resulted in a type like `>::Out`; normalizing this type requires knowing the +// value of `_`; solving that requires having normalized, so we can +// test against `C: NodeCodec` in the environment. +// +// run-pass + +pub trait Hasher { + type Out: Eq; +} + +pub trait NodeCodec { + const HASHED_NULL_NODE: H::Out; +} + +pub trait Trie> { + /// Returns the root of the trie. + fn root(&self) -> &H::Out; + + /// Is the trie empty? + fn is_empty(&self) -> bool { *self.root() == C::HASHED_NULL_NODE } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs new file mode 100644 index 000000000..c71937a50 --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.rs @@ -0,0 +1,68 @@ +// This test is ensuring that type ascriptions on let bindings +// constrain both: +// +// 1. the input expression on the right-hand side (after any potential +// coercion, and allowing for covariance), *and* +// +// 2. the bindings (if any) nested within the pattern on the left-hand +// side (and here, the type-constraint is *invariant*). + +#![allow(dead_code, unused_mut)] +type PairUncoupled<'a, 'b, T> = (&'a T, &'b T); +type PairCoupledRegions<'a, T> = (&'a T, &'a T); +type PairCoupledTypes = (T, T); + +fn uncoupled_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((mut y, mut _z),): (PairUncoupled,) = ((s, &_x),); // ok + // Above compiling does *not* imply below would compile. + // ::std::mem::swap(&mut y, &mut _z); + y +} + +fn swap_regions((mut y, mut _z): PairCoupledRegions) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledRegions,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_regions((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_types((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<&u32>,) = ((s, &_x),); + // If above line compiled, so should line below ... + + // swap_types((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn swap_wilds((mut y, mut _z): PairCoupledTypes<&u32>) { + ::std::mem::swap(&mut y, &mut _z); +} + +fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),): (PairCoupledTypes<_>,) = ((s, &_x),); + // If above line compiled, so should line below + // swap_wilds((y, _z)); + + // ... but the ascribed type also invalidates this use of `y` + y //~ ERROR lifetime may not live long enough +} + +fn main() { + uncoupled_lhs(&3, &4); + coupled_regions_lhs(&3, &4); + coupled_types_lhs(&3, &4); + coupled_wilds_lhs(&3, &4); +} diff --git a/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr new file mode 100644 index 000000000..8399ef04e --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-55748-pat-types-constrain-bindings.stderr @@ -0,0 +1,29 @@ +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:33:5 + | +LL | fn coupled_regions_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:47:5 + | +LL | fn coupled_types_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-55748-pat-types-constrain-bindings.rs:60:5 + | +LL | fn coupled_wilds_lhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to 3 previous errors + diff --git a/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs b/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs new file mode 100644 index 000000000..9b3ec702c --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.rs @@ -0,0 +1,40 @@ +// Check that repeated type variables are correctly handled + +#![allow(unused)] +#![feature(type_ascription)] + +type PairUncoupled<'a, 'b, T> = (&'a T, &'b T); +type PairCoupledTypes = (T, T); +type PairCoupledRegions<'a, T> = (&'a T, &'a T); + +fn uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),): (PairUncoupled<_>,); + y // OK +} + +fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,); + y //~ ERROR lifetime may not live long enough +} + +fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,); + y //~ ERROR lifetime may not live long enough +} + +fn cast_uncoupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),) as (PairUncoupled<_>,); + y // OK +} + +fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,); + y //~ ERROR lifetime may not live long enough +} + +fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,); + y //~ ERROR lifetime may not live long enough +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.stderr b/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.stderr new file mode 100644 index 000000000..c99f53c5a --- /dev/null +++ b/src/test/ui/nll/user-annotations/issue-57731-ascibed-coupled-types.stderr @@ -0,0 +1,38 @@ +error: lifetime may not live long enough + --> $DIR/issue-57731-ascibed-coupled-types.rs:17:5 + | +LL | fn coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let ((y, _z),) = ((s, _x),): (PairCoupledTypes<_>,); +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-57731-ascibed-coupled-types.rs:22:5 + | +LL | fn coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let ((y, _z),) = ((s, _x),): (PairCoupledRegions<_>,); +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-57731-ascibed-coupled-types.rs:32:5 + | +LL | fn cast_coupled_wilds_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let ((y, _z),) = ((s, _x),) as (PairCoupledTypes<_>,); +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/issue-57731-ascibed-coupled-types.rs:37:5 + | +LL | fn cast_coupled_regions_rhs<'a>(_x: &'a u32, s: &'static u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let ((y, _z),) = ((s, _x),) as (PairCoupledRegions<_>,); +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: aborting due to 4 previous errors + diff --git a/src/test/ui/nll/user-annotations/method-call.rs b/src/test/ui/nll/user-annotations/method-call.rs new file mode 100644 index 000000000..beafc597a --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-call.rs @@ -0,0 +1,69 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +trait Bazoom { + fn method(&self, arg: T, arg2: U) { } +} + +impl Bazoom for T { +} + +fn no_annot() { + let a = 22; + let b = 44; + let c = 66; + a.method(b, &c); // OK +} + +fn annot_underscore() { + let a = 22; + let b = 44; + let c = 66; + a.method::<_>(b, &c); // OK +} + +fn annot_reference_any_lifetime() { + let a = 22; + let b = 44; + let c = 66; + a.method::<&u32>(b, &c); // OK +} + +fn annot_reference_static_lifetime() { + let a = 22; + let b = 44; + let c = 66; + a.method::<&'static u32>(b, &c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let a = 22; + let b = 44; + let c = 66; + a.method::<&'a u32>(b, &c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + let a = 22; + let b = 44; + a.method::<&'a u32>(b, c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + let c = 66; + a.method::<&'a u32>(b, &c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + a.method::<&'a u32>(b, c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/method-call.stderr b/src/test/ui/nll/user-annotations/method-call.stderr new file mode 100644 index 000000000..fcaeb465d --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-call.stderr @@ -0,0 +1,43 @@ +error[E0597]: `c` does not live long enough + --> $DIR/method-call.rs:36:34 + | +LL | a.method::<&'static u32>(b, &c); + | -----------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/method-call.rs:43:29 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | a.method::<&'a u32>(b, &c); + | ------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/method-call.rs:57:33 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | let _closure = || { + | - `c` dropped here while still borrowed +LL | let c = 66; +LL | a.method::<&'a u32>(b, &c); + | ------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-1.rs b/src/test/ui/nll/user-annotations/method-ufcs-1.rs new file mode 100644 index 000000000..950771f35 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-1.rs @@ -0,0 +1,63 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +trait Bazoom: Sized { + fn method(self, arg: T, arg2: U) { } +} + +impl Bazoom for T { +} + +fn annot_underscore() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method::<_>(&a, b, c); // OK +} + +fn annot_reference_any_lifetime() { + let a = 22; + let b = 44; + let c = 66; + <&u32 as Bazoom<_>>::method(&a, b, c); // OK +} + +fn annot_reference_static_lifetime() { + let a = 22; + let b = 44; + let c = 66; + let x = <&'static u32 as Bazoom<_>>::method; + x(&a, b, c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let a = 22; + let b = 44; + let c = 66; + <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(a: &'a u32) { + let b = 44; + let c = 66; + <&'a u32 as Bazoom<_>>::method(&a, b, c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + let c = 66; + <&'a u32 as Bazoom<_>>::method(&a, b, c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(a: &'a u32) { + let b = 44; + let c = 66; + let _closure = || { + <&'a u32 as Bazoom<_>>::method(&a, b, c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/method-ufcs-1.stderr b/src/test/ui/nll/user-annotations/method-ufcs-1.stderr new file mode 100644 index 000000000..962ddfd2b --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-1.stderr @@ -0,0 +1,46 @@ +error[E0597]: `a` does not live long enough + --> $DIR/method-ufcs-1.rs:30:7 + | +LL | x(&a, b, c); + | --^^------- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'static` +LL | } + | - `a` dropped here while still borrowed + +error[E0597]: `a` does not live long enough + --> $DIR/method-ufcs-1.rs:37:36 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); + | -------------------------------^^------- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'a` +LL | } + | - `a` dropped here while still borrowed + +error[E0597]: `a` does not live long enough + --> $DIR/method-ufcs-1.rs:51:41 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | let _closure = || { + | -- value captured here +LL | let c = 66; +LL | <&'a u32 as Bazoom<_>>::method(&a, b, c); + | --------------------------------^------- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'a` +LL | }; +LL | } + | - `a` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-2.rs b/src/test/ui/nll/user-annotations/method-ufcs-2.rs new file mode 100644 index 000000000..7dc0f0c12 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-2.rs @@ -0,0 +1,63 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +trait Bazoom: Sized { + fn method(self, arg: T, arg2: U) { } +} + +impl Bazoom for T { +} + +fn annot_underscore() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method(a, &b, c); // OK +} + +fn annot_reference_any_lifetime() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<&u32>>::method(a, &b, c); // OK +} + +fn annot_reference_static_lifetime() { + let a = 22; + let b = 44; + let c = 66; + let x = <&'static u32 as Bazoom<_>>::method; + x(&a, b, c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(b: &'a u32) { + let a = 44; + let c = 66; + <_ as Bazoom<&'a u32>>::method(a, &b, c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + let c = 66; + <_ as Bazoom<&'a u32>>::method(a, &b, c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(b: &'a u32) { + let a = 44; + let c = 66; + let _closure = || { + <_ as Bazoom<&'a u32>>::method(a, &b, c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/method-ufcs-2.stderr b/src/test/ui/nll/user-annotations/method-ufcs-2.stderr new file mode 100644 index 000000000..63d59905e --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-2.stderr @@ -0,0 +1,46 @@ +error[E0597]: `a` does not live long enough + --> $DIR/method-ufcs-2.rs:30:7 + | +LL | x(&a, b, c); + | --^^------- + | | | + | | borrowed value does not live long enough + | argument requires that `a` is borrowed for `'static` +LL | } + | - `a` dropped here while still borrowed + +error[E0597]: `b` does not live long enough + --> $DIR/method-ufcs-2.rs:37:39 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); + | ----------------------------------^^---- + | | | + | | borrowed value does not live long enough + | argument requires that `b` is borrowed for `'a` +LL | } + | - `b` dropped here while still borrowed + +error[E0597]: `b` does not live long enough + --> $DIR/method-ufcs-2.rs:51:44 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | let _closure = || { + | -- value captured here +LL | let c = 66; +LL | <_ as Bazoom<&'a u32>>::method(a, &b, c); + | -----------------------------------^---- + | | | + | | borrowed value does not live long enough + | argument requires that `b` is borrowed for `'a` +LL | }; +LL | } + | - `b` dropped here while still borrowed + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-3.rs b/src/test/ui/nll/user-annotations/method-ufcs-3.rs new file mode 100644 index 000000000..59d2009d1 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-3.rs @@ -0,0 +1,69 @@ +// Unit test for the "user substitutions" that are annotated on each +// node. + +trait Bazoom { + fn method(&self, arg: T, arg2: U) { } +} + +impl Bazoom for T { +} + +fn no_annot() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method(&a, b, &c); // OK +} + +fn annot_underscore() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method::<_>(&a, b, &c); // OK +} + +fn annot_reference_any_lifetime() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method::<&u32>(&a, b, &c); // OK +} + +fn annot_reference_static_lifetime() { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method::<&'static u32>(&a, b, &c); //~ ERROR +} + +fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + let a = 22; + let b = 44; + let c = 66; + <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); //~ ERROR +} + +fn annot_reference_named_lifetime_ok<'a>(c: &'a u32) { + let a = 22; + let b = 44; + <_ as Bazoom<_>>::method::<&'a u32>(&a, b, c); +} + +fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + let c = 66; + <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); //~ ERROR + }; +} + +fn annot_reference_named_lifetime_in_closure_ok<'a>(c: &'a u32) { + let a = 22; + let b = 44; + let _closure = || { + <_ as Bazoom<_>>::method::<&'a u32>(&a, b, c); + }; +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/method-ufcs-3.stderr b/src/test/ui/nll/user-annotations/method-ufcs-3.stderr new file mode 100644 index 000000000..328dde980 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-3.stderr @@ -0,0 +1,43 @@ +error[E0597]: `c` does not live long enough + --> $DIR/method-ufcs-3.rs:36:53 + | +LL | <_ as Bazoom<_>>::method::<&'static u32>(&a, b, &c); + | ------------------------------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'static` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/method-ufcs-3.rs:43:48 + | +LL | fn annot_reference_named_lifetime<'a>(_d: &'a u32) { + | -- lifetime `'a` defined here +... +LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); + | -------------------------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` +LL | } + | - `c` dropped here while still borrowed + +error[E0597]: `c` does not live long enough + --> $DIR/method-ufcs-3.rs:57:52 + | +LL | fn annot_reference_named_lifetime_in_closure<'a>(_: &'a u32) { + | -- lifetime `'a` defined here +... +LL | let _closure = || { + | - `c` dropped here while still borrowed +LL | let c = 66; +LL | <_ as Bazoom<_>>::method::<&'a u32>(&a, b, &c); + | -------------------------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `c` is borrowed for `'a` + +error: aborting due to 3 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.rs b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.rs new file mode 100644 index 000000000..7bfed61d4 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.rs @@ -0,0 +1,18 @@ +// Check that substitutions given on the self type (here, `A`) carry +// through to NLL. + +struct A<'a> { x: &'a u32 } + +impl<'a> A<'a> { + fn new<'b, T>(x: &'a u32, y: T) -> Self { + Self { x } + } +} + +fn foo<'a>() { + let v = 22; + let x = A::<'a>::new(&v, 22); + //~^ ERROR +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr new file mode 100644 index 000000000..94861babd --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-1.stderr @@ -0,0 +1,18 @@ +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-1.rs:14:26 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = A::<'a>::new(&v, 22); + | -------------^^----- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +LL | +LL | } + | - `v` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.rs b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.rs new file mode 100644 index 000000000..cfbc0bcf6 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.rs @@ -0,0 +1,19 @@ +// Check that substitutions given on the self type (here, `A`) can be +// used in combination with annotations given for method arguments. + +struct A<'a> { x: &'a u32 } + +impl<'a> A<'a> { + fn new<'b, T>(x: &'a u32, y: T) -> Self { + Self { x } + } +} + +fn foo<'a>() { + let v = 22; + let x = A::<'a>::new::<&'a u32>(&v, &v); + //~^ ERROR + //~| ERROR +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr new file mode 100644 index 000000000..06f20d9b2 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-2.stderr @@ -0,0 +1,33 @@ +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-2.rs:14:37 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = A::<'a>::new::<&'a u32>(&v, &v); + | ------------------------^^----- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +... +LL | } + | - `v` dropped here while still borrowed + +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-2.rs:14:41 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = A::<'a>::new::<&'a u32>(&v, &v); + | ----------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +... +LL | } + | - `v` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.rs b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.rs new file mode 100644 index 000000000..7ddb13360 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.rs @@ -0,0 +1,18 @@ +// Check that inherent methods invoked with `::new` style +// carry their annotations through to NLL. + +struct A<'a> { x: &'a u32 } + +impl<'a> A<'a> { + fn new<'b, T>(x: &'a u32, y: T) -> Self { + Self { x } + } +} + +fn foo<'a>() { + let v = 22; + let x = >::new(&v, 22); + //~^ ERROR +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr new file mode 100644 index 000000000..4ad61dc81 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-3.stderr @@ -0,0 +1,18 @@ +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-3.rs:14:26 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = >::new(&v, 22); + | -------------^^----- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +LL | +LL | } + | - `v` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.rs b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.rs new file mode 100644 index 000000000..85e759739 --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.rs @@ -0,0 +1,20 @@ +// Check that inherent methods invoked with `::new` style +// carry their annotations through to NLL in connection with +// method type parameters. + +struct A<'a> { x: &'a u32 } + +impl<'a> A<'a> { + fn new<'b, T>(x: &'a u32, y: T) -> Self { + Self { x } + } +} + +fn foo<'a>() { + let v = 22; + let x = >::new::<&'a u32>(&v, &v); + //~^ ERROR + //~| ERROR +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr new file mode 100644 index 000000000..0f83e99cd --- /dev/null +++ b/src/test/ui/nll/user-annotations/method-ufcs-inherent-4.stderr @@ -0,0 +1,33 @@ +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-4.rs:15:37 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = >::new::<&'a u32>(&v, &v); + | ------------------------^^----- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +... +LL | } + | - `v` dropped here while still borrowed + +error[E0597]: `v` does not live long enough + --> $DIR/method-ufcs-inherent-4.rs:15:41 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let v = 22; +LL | let x = >::new::<&'a u32>(&v, &v); + | ----------------------------^^- + | | | + | | borrowed value does not live long enough + | argument requires that `v` is borrowed for `'a` +... +LL | } + | - `v` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/normalization.rs b/src/test/ui/nll/user-annotations/normalization.rs new file mode 100644 index 000000000..870e3d811 --- /dev/null +++ b/src/test/ui/nll/user-annotations/normalization.rs @@ -0,0 +1,10 @@ +// Test that we enforce a `&'static` requirement that is only visible +// after normalization. + +trait Foo { type Out; } +impl Foo for () { type Out = &'static u32; } + +fn main() { + let a = 22; + let b: <() as Foo>::Out = &a; //~ ERROR +} diff --git a/src/test/ui/nll/user-annotations/normalization.stderr b/src/test/ui/nll/user-annotations/normalization.stderr new file mode 100644 index 000000000..4c7893789 --- /dev/null +++ b/src/test/ui/nll/user-annotations/normalization.stderr @@ -0,0 +1,13 @@ +error[E0597]: `a` does not live long enough + --> $DIR/normalization.rs:9:31 + | +LL | let b: <() as Foo>::Out = &a; + | ---------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `a` is borrowed for `'static` +LL | } + | - `a` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/normalize-self-ty.rs b/src/test/ui/nll/user-annotations/normalize-self-ty.rs new file mode 100644 index 000000000..df905c878 --- /dev/null +++ b/src/test/ui/nll/user-annotations/normalize-self-ty.rs @@ -0,0 +1,23 @@ +// Regression test for #55183: check a case where the self type from +// the inherent impl requires normalization to be equal to the +// user-provided type. +// +// check-pass + +trait Mirror { + type Me; +} + +impl Mirror for T { + type Me = T; +} + +struct Foo(A, B); + +impl Foo::Me> { + fn m(_: A) { } +} + +fn main() { + >::m(&22); +} diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.rs b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.rs new file mode 100644 index 000000000..59cd69c0c --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.rs @@ -0,0 +1,22 @@ +enum Foo<'a> { + Bar { field: &'a u32 } +} + +fn in_let() { + let y = 22; + let foo = Foo::Bar { field: &y }; + //~^ ERROR `y` does not live long enough + let Foo::Bar::<'static> { field: _z } = foo; +} + +fn in_match() { + let y = 22; + let foo = Foo::Bar { field: &y }; + //~^ ERROR `y` does not live long enough + match foo { + Foo::Bar::<'static> { field: _z } => { + } + } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr new file mode 100644 index 000000000..a97e7a9fd --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_enum_variant.stderr @@ -0,0 +1,26 @@ +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_brace_enum_variant.rs:7:33 + | +LL | let foo = Foo::Bar { field: &y }; + | ^^ borrowed value does not live long enough +LL | +LL | let Foo::Bar::<'static> { field: _z } = foo; + | --------------------------------- type annotation requires that `y` is borrowed for `'static` +LL | } + | - `y` dropped here while still borrowed + +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_brace_enum_variant.rs:14:33 + | +LL | let foo = Foo::Bar { field: &y }; + | ^^ borrowed value does not live long enough +... +LL | Foo::Bar::<'static> { field: _z } => { + | --------------------------------- type annotation requires that `y` is borrowed for `'static` +... +LL | } + | - `y` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.rs b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.rs new file mode 100644 index 000000000..1586c4ea3 --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.rs @@ -0,0 +1,20 @@ +struct Foo<'a> { field: &'a u32 } + +fn in_let() { + let y = 22; + let foo = Foo { field: &y }; + //~^ ERROR `y` does not live long enough + let Foo::<'static> { field: _z } = foo; +} + +fn in_main() { + let y = 22; + let foo = Foo { field: &y }; + //~^ ERROR `y` does not live long enough + match foo { + Foo::<'static> { field: _z } => { + } + } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr new file mode 100644 index 000000000..408d7c2a5 --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_brace_struct.stderr @@ -0,0 +1,26 @@ +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_brace_struct.rs:5:28 + | +LL | let foo = Foo { field: &y }; + | ^^ borrowed value does not live long enough +LL | +LL | let Foo::<'static> { field: _z } = foo; + | ---------------------------- type annotation requires that `y` is borrowed for `'static` +LL | } + | - `y` dropped here while still borrowed + +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_brace_struct.rs:12:28 + | +LL | let foo = Foo { field: &y }; + | ^^ borrowed value does not live long enough +... +LL | Foo::<'static> { field: _z } => { + | ---------------------------- type annotation requires that `y` is borrowed for `'static` +... +LL | } + | - `y` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.rs b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.rs new file mode 100644 index 000000000..6fa59fdd8 --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.rs @@ -0,0 +1,22 @@ +enum Foo<'a> { + Bar(&'a u32) +} + +fn in_let() { + let y = 22; + let foo = Foo::Bar(&y); + //~^ ERROR `y` does not live long enough + let Foo::Bar::<'static>(_z) = foo; +} + +fn in_match() { + let y = 22; + let foo = Foo::Bar(&y); + //~^ ERROR `y` does not live long enough + match foo { + Foo::Bar::<'static>(_z) => { + } + } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr new file mode 100644 index 000000000..920c906f6 --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_enum_variant.stderr @@ -0,0 +1,26 @@ +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_tuple_enum_variant.rs:7:24 + | +LL | let foo = Foo::Bar(&y); + | ^^ borrowed value does not live long enough +LL | +LL | let Foo::Bar::<'static>(_z) = foo; + | ----------------------- type annotation requires that `y` is borrowed for `'static` +LL | } + | - `y` dropped here while still borrowed + +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_tuple_enum_variant.rs:14:24 + | +LL | let foo = Foo::Bar(&y); + | ^^ borrowed value does not live long enough +... +LL | Foo::Bar::<'static>(_z) => { + | ----------------------- type annotation requires that `y` is borrowed for `'static` +... +LL | } + | - `y` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.rs b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.rs new file mode 100644 index 000000000..7486aab0e --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.rs @@ -0,0 +1,20 @@ +struct Foo<'a>(&'a u32); + +fn in_let() { + let y = 22; + let foo = Foo(&y); + //~^ ERROR `y` does not live long enough + let Foo::<'static>(_z) = foo; +} + +fn in_match() { + let y = 22; + let foo = Foo(&y); + //~^ ERROR `y` does not live long enough + match foo { + Foo::<'static>(_z) => { + } + } +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr new file mode 100644 index 000000000..3f01638d8 --- /dev/null +++ b/src/test/ui/nll/user-annotations/pattern_substs_on_tuple_struct.stderr @@ -0,0 +1,26 @@ +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_tuple_struct.rs:5:19 + | +LL | let foo = Foo(&y); + | ^^ borrowed value does not live long enough +LL | +LL | let Foo::<'static>(_z) = foo; + | ------------------ type annotation requires that `y` is borrowed for `'static` +LL | } + | - `y` dropped here while still borrowed + +error[E0597]: `y` does not live long enough + --> $DIR/pattern_substs_on_tuple_struct.rs:12:19 + | +LL | let foo = Foo(&y); + | ^^ borrowed value does not live long enough +... +LL | Foo::<'static>(_z) => { + | ------------------ type annotation requires that `y` is borrowed for `'static` +... +LL | } + | - `y` dropped here while still borrowed + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/patterns.rs b/src/test/ui/nll/user-annotations/patterns.rs new file mode 100644 index 000000000..1f635d7f5 --- /dev/null +++ b/src/test/ui/nll/user-annotations/patterns.rs @@ -0,0 +1,136 @@ +// Test that various patterns also enforce types. + +fn variable_no_initializer() { + let x = 22; + let y: &'static u32; + y = &x; //~ ERROR +} + +fn tuple_no_initializer() { + + + let x = 22; + let (y, z): (&'static u32, &'static u32); + y = &x; //~ ERROR +} + +fn ref_with_ascribed_static_type() -> u32 { + // Check the behavior in some wacky cases. + let x = 22; + let y = &x; //~ ERROR + let ref z: &'static u32 = y; + **z +} + +fn ref_with_ascribed_any_type() -> u32 { + let x = 22; + let y = &x; + let ref z: &u32 = y; + **z +} + +struct Single { value: T } + +fn struct_no_initializer() { + + + let x = 22; + let Single { value: y }: Single<&'static u32>; + y = &x; //~ ERROR +} + + +fn struct_no_initializer_must_normalize() { + trait Indirect { type Assoc; } + struct StaticU32; + impl Indirect for StaticU32 { type Assoc = &'static u32; } + struct Single2 { value: ::Assoc } + + let x = 22; + let Single2 { value: mut _y }: Single2; + _y = &x; //~ ERROR +} + +fn variable_with_initializer() { + let x = 22; + let y: &'static u32 = &x; //~ ERROR +} + +fn underscore_with_initializer() { + let x = 22; + let _: &'static u32 = &x; //~ ERROR + + let _: Vec<&'static String> = vec![&String::new()]; + //~^ ERROR temporary value dropped while borrowed [E0716] + + let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); + //~^ ERROR temporary value dropped while borrowed [E0716] + + let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); + //~^ ERROR temporary value dropped while borrowed [E0716] +} + +fn pair_underscores_with_initializer() { + let x = 22; + let (_, _): (&'static u32, u32) = (&x, 44); //~ ERROR +} + +fn pair_variable_with_initializer() { + let x = 22; + let (y, _): (&'static u32, u32) = (&x, 44); //~ ERROR +} + +fn struct_single_field_variable_with_initializer() { + let x = 22; + let Single { value: y }: Single<&'static u32> = Single { value: &x }; //~ ERROR +} + +fn struct_single_field_underscore_with_initializer() { + let x = 22; + let Single { value: _ }: Single<&'static u32> = Single { value: &x }; //~ ERROR +} + +struct Double { value1: T, value2: T } + +fn struct_double_field_underscore_with_initializer() { + let x = 22; + let Double { value1: _, value2: _ }: Double<&'static u32> = Double { + value1: &x, //~ ERROR + value2: &44, + }; +} + +fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 { + + + + + + + let y: &'a u32 = &22; + y //~ ERROR +} + +fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { + + + + + + + + let (y, _z): (&'a u32, u32) = (&22, 44); + y //~ ERROR +} + +fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 { + let Single { value: y }: Single<&'a u32> = Single { value: &22 }; + y //~ ERROR +} + +fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { + let (y, _z): (&'static u32, u32) = (x, 44); //~ ERROR + y +} + +fn main() { } diff --git a/src/test/ui/nll/user-annotations/patterns.stderr b/src/test/ui/nll/user-annotations/patterns.stderr new file mode 100644 index 000000000..60d6e6db3 --- /dev/null +++ b/src/test/ui/nll/user-annotations/patterns.stderr @@ -0,0 +1,189 @@ +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:6:9 + | +LL | let y: &'static u32; + | ------------ type annotation requires that `x` is borrowed for `'static` +LL | y = &x; + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:14:9 + | +LL | let (y, z): (&'static u32, &'static u32); + | ---------------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:20:13 + | +LL | let y = &x; + | ^^ borrowed value does not live long enough +LL | let ref z: &'static u32 = y; + | ------------ type annotation requires that `x` is borrowed for `'static` +LL | **z +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:39:9 + | +LL | let Single { value: y }: Single<&'static u32>; + | -------------------- type annotation requires that `x` is borrowed for `'static` +LL | y = &x; + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:51:10 + | +LL | let Single2 { value: mut _y }: Single2; + | ------------------ type annotation requires that `x` is borrowed for `'static` +LL | _y = &x; + | ^^ borrowed value does not live long enough +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:56:27 + | +LL | let y: &'static u32 = &x; + | ------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:61:27 + | +LL | let _: &'static u32 = &x; + | ------------ ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +... +LL | } + | - `x` dropped here while still borrowed + +error[E0716]: temporary value dropped while borrowed + --> $DIR/patterns.rs:63:41 + | +LL | let _: Vec<&'static String> = vec![&String::new()]; + | -------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/patterns.rs:66:52 + | +LL | let (_, a): (Vec<&'static String>, _) = (vec![&String::new()], 44); + | ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0716]: temporary value dropped while borrowed + --> $DIR/patterns.rs:69:53 + | +LL | let (_a, b): (Vec<&'static String>, _) = (vec![&String::new()], 44); + | ------------------------- ^^^^^^^^^^^^^ - temporary value is freed at the end of this statement + | | | + | | creates a temporary which is freed while still in use + | type annotation requires that borrow lasts for `'static` + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:75:40 + | +LL | let (_, _): (&'static u32, u32) = (&x, 44); + | ------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:80:40 + | +LL | let (y, _): (&'static u32, u32) = (&x, 44); + | ------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:85:69 + | +LL | let Single { value: y }: Single<&'static u32> = Single { value: &x }; + | -------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:90:69 + | +LL | let Single { value: _ }: Single<&'static u32> = Single { value: &x }; + | -------------------- ^^ borrowed value does not live long enough + | | + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error[E0597]: `x` does not live long enough + --> $DIR/patterns.rs:98:17 + | +LL | let Double { value1: _, value2: _ }: Double<&'static u32> = Double { + | -------------------- type annotation requires that `x` is borrowed for `'static` +LL | value1: &x, + | ^^ borrowed value does not live long enough +... +LL | } + | - `x` dropped here while still borrowed + +error: lifetime may not live long enough + --> $DIR/patterns.rs:111:5 + | +LL | fn static_to_a_to_static_through_variable<'a>(x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/patterns.rs:123:5 + | +LL | fn static_to_a_to_static_through_tuple<'a>(x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +... +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/patterns.rs:128:5 + | +LL | fn static_to_a_to_static_through_struct<'a>(_x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let Single { value: y }: Single<&'a u32> = Single { value: &22 }; +LL | y + | ^ returning this value requires that `'a` must outlive `'static` + +error: lifetime may not live long enough + --> $DIR/patterns.rs:132:18 + | +LL | fn a_to_static_then_static<'a>(x: &'a u32) -> &'static u32 { + | -- lifetime `'a` defined here +LL | let (y, _z): (&'static u32, u32) = (x, 44); + | ^^^^^^^^^^^^^^^^^^^ type annotation requires that `'a` must outlive `'static` + +error: aborting due to 19 previous errors + +Some errors have detailed explanations: E0597, E0716. +For more information about an error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/promoted-annotation.rs b/src/test/ui/nll/user-annotations/promoted-annotation.rs new file mode 100644 index 000000000..b92f8bfd2 --- /dev/null +++ b/src/test/ui/nll/user-annotations/promoted-annotation.rs @@ -0,0 +1,10 @@ +// Test that type annotations are checked in promoted constants correctly. + +fn foo<'a>() { + let x = 0; + let f = &drop::<&'a i32>; + f(&x); + //~^ ERROR `x` does not live long enough +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/promoted-annotation.stderr b/src/test/ui/nll/user-annotations/promoted-annotation.stderr new file mode 100644 index 000000000..cb99a6a36 --- /dev/null +++ b/src/test/ui/nll/user-annotations/promoted-annotation.stderr @@ -0,0 +1,17 @@ +error[E0597]: `x` does not live long enough + --> $DIR/promoted-annotation.rs:6:7 + | +LL | fn foo<'a>() { + | -- lifetime `'a` defined here +LL | let x = 0; +LL | let f = &drop::<&'a i32>; + | ---------------- assignment requires that `x` is borrowed for `'a` +LL | f(&x); + | ^^ borrowed value does not live long enough +LL | +LL | } + | - `x` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/type-annotation-with-hrtb.rs b/src/test/ui/nll/user-annotations/type-annotation-with-hrtb.rs new file mode 100644 index 000000000..1f7c06038 --- /dev/null +++ b/src/test/ui/nll/user-annotations/type-annotation-with-hrtb.rs @@ -0,0 +1,33 @@ +// Regression test for issue #69490 + +// check-pass + +pub trait Trait { + const S: &'static str; +} + +impl Trait<()> for T +where + T: for<'a> Trait<&'a ()>, +{ + // Use of `T::S` here caused an ICE + const S: &'static str = T::S; +} + +// Some similar cases that didn't ICE: + +impl<'a, T> Trait<()> for (T,) +where + T: Trait<&'a ()>, +{ + const S: &'static str = T::S; +} + +impl Trait<()> for [T; 1] +where + T: Trait fn(&'a ())>, +{ + const S: &'static str = T::S; +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs new file mode 100644 index 000000000..101b5cfab --- /dev/null +++ b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.rs @@ -0,0 +1,7 @@ +#![allow(warnings)] +#![feature(type_ascription)] + +fn main() { + let x = 22_u32; + let y: &u32 = &x: &'static u32; //~ ERROR E0597 +} diff --git a/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr new file mode 100644 index 000000000..133bbef52 --- /dev/null +++ b/src/test/ui/nll/user-annotations/type_ascription_static_lifetime.stderr @@ -0,0 +1,14 @@ +error[E0597]: `x` does not live long enough + --> $DIR/type_ascription_static_lifetime.rs:6:19 + | +LL | let y: &u32 = &x: &'static u32; + | ^^-------------- + | | + | borrowed value does not live long enough + | type annotation requires that `x` is borrowed for `'static` +LL | } + | - `x` dropped here while still borrowed + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0597`. diff --git a/src/test/ui/nll/user-annotations/wf-self-type.rs b/src/test/ui/nll/user-annotations/wf-self-type.rs new file mode 100644 index 000000000..539226aab --- /dev/null +++ b/src/test/ui/nll/user-annotations/wf-self-type.rs @@ -0,0 +1,13 @@ +struct Foo<'a, 'b: 'a>(&'a &'b ()); + +impl<'a, 'b> Foo<'a, 'b> { + fn xmute(a: &'b ()) -> &'a () { + unreachable!() + } +} + +pub fn foo<'a, 'b>(u: &'b ()) -> &'a () { + Foo::xmute(u) //~ ERROR lifetime may not live long enough +} + +fn main() {} diff --git a/src/test/ui/nll/user-annotations/wf-self-type.stderr b/src/test/ui/nll/user-annotations/wf-self-type.stderr new file mode 100644 index 000000000..1d3ae7cfb --- /dev/null +++ b/src/test/ui/nll/user-annotations/wf-self-type.stderr @@ -0,0 +1,14 @@ +error: lifetime may not live long enough + --> $DIR/wf-self-type.rs:10:5 + | +LL | pub fn foo<'a, 'b>(u: &'b ()) -> &'a () { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | Foo::xmute(u) + | ^^^^^^^^^^^^^ function was supposed to return data with lifetime `'a` but it is returning data with lifetime `'b` + | + = help: consider adding the following bound: `'b: 'a` + +error: aborting due to previous error + -- cgit v1.2.3