diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-18 02:49:42 +0000 |
commit | 837b550238aa671a591ccf282dddeab29cadb206 (patch) | |
tree | 914b6b8862bace72bd3245ca184d374b08d8a672 /tests/ui/fn | |
parent | Adding debian version 1.70.0+dfsg2-1. (diff) | |
download | rustc-837b550238aa671a591ccf282dddeab29cadb206.tar.xz rustc-837b550238aa671a591ccf282dddeab29cadb206.zip |
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/fn')
-rw-r--r-- | tests/ui/fn/fn-item-lifetime-bounds.rs | 37 | ||||
-rw-r--r-- | tests/ui/fn/implied-bounds-impl-header-projections.rs | 31 | ||||
-rw-r--r-- | tests/ui/fn/issue-3099.rs | 11 | ||||
-rw-r--r-- | tests/ui/fn/issue-3099.stderr | 14 |
4 files changed, 93 insertions, 0 deletions
diff --git a/tests/ui/fn/fn-item-lifetime-bounds.rs b/tests/ui/fn/fn-item-lifetime-bounds.rs new file mode 100644 index 000000000..68a1d0ce9 --- /dev/null +++ b/tests/ui/fn/fn-item-lifetime-bounds.rs @@ -0,0 +1,37 @@ +// check-pass +// known-bug: #84533 + +// Should fail. Lifetimes are checked correctly when `foo` is called, but NOT +// when only the lifetime parameters are instantiated. + +use std::marker::PhantomData; + +#[allow(dead_code)] +fn foo<'b, 'a>() -> PhantomData<&'b &'a ()> { + PhantomData +} + +#[allow(dead_code)] +#[allow(path_statements)] +fn caller<'b, 'a>() { + foo::<'b, 'a>; +} + +// In contrast to above, below code correctly does NOT compile. +// fn caller<'b, 'a>() { +// foo::<'b, 'a>(); +// } + +// error: lifetime may not live long enough +// --> src/main.rs:22:5 +// | +// 21 | fn caller<'b, 'a>() { +// | -- -- lifetime `'a` defined here +// | | +// | lifetime `'b` defined here +// 22 | foo::<'b, 'a>(); +// | ^^^^^^^^^^^^^^^ requires that `'a` must outlive `'b` +// | +// = help: consider adding the following bound: `'a: 'b` + +fn main() {} diff --git a/tests/ui/fn/implied-bounds-impl-header-projections.rs b/tests/ui/fn/implied-bounds-impl-header-projections.rs new file mode 100644 index 000000000..28cec8050 --- /dev/null +++ b/tests/ui/fn/implied-bounds-impl-header-projections.rs @@ -0,0 +1,31 @@ +// check-pass +// known-bug: #100051 + +// Should fail. Implied bounds from projections in impl headers can create +// improper lifetimes. Variant of issue #98543 which was fixed by #99217. + +trait Trait { + type Type; +} + +impl<T> Trait for T { + type Type = (); +} + +trait Extend<'a, 'b> { + fn extend(self, s: &'a str) -> &'b str; +} + +impl<'a, 'b> Extend<'a, 'b> for <&'b &'a () as Trait>::Type +where + for<'what, 'ever> &'what &'ever (): Trait, +{ + fn extend(self, s: &'a str) -> &'b str { + s + } +} + +fn main() { + let y = <() as Extend<'_, '_>>::extend((), &String::from("Hello World")); + println!("{}", y); +} diff --git a/tests/ui/fn/issue-3099.rs b/tests/ui/fn/issue-3099.rs new file mode 100644 index 000000000..ee75b3593 --- /dev/null +++ b/tests/ui/fn/issue-3099.rs @@ -0,0 +1,11 @@ +fn a(x: String) -> String { + format!("First function with {}", x) +} + +fn a(x: String, y: String) -> String { //~ ERROR the name `a` is defined multiple times + format!("Second function with {} and {}", x, y) +} + +fn main() { + println!("Result: "); +} diff --git a/tests/ui/fn/issue-3099.stderr b/tests/ui/fn/issue-3099.stderr new file mode 100644 index 000000000..32ee2e1d2 --- /dev/null +++ b/tests/ui/fn/issue-3099.stderr @@ -0,0 +1,14 @@ +error[E0428]: the name `a` is defined multiple times + --> $DIR/issue-3099.rs:5:1 + | +LL | fn a(x: String) -> String { + | ------------------------- previous definition of the value `a` here +... +LL | fn a(x: String, y: String) -> String { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `a` redefined here + | + = note: `a` must be defined only once in the value namespace of this module + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0428`. |