From 64d98f8ee037282c35007b64c2649055c56af1db Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:03 +0200 Subject: Merging upstream version 1.68.2+dfsg1. Signed-off-by: Daniel Baumann --- .../auxiliary/upstream_alias.rs | 5 +++++ tests/ui/late-bound-lifetimes/cross_crate_alias.rs | 10 +++++++++ .../downgraded_to_early_through_alias.rs | 24 +++++++++++++++++++++ tests/ui/late-bound-lifetimes/issue-36381.rs | 25 ++++++++++++++++++++++ tests/ui/late-bound-lifetimes/issue-47511.rs | 21 ++++++++++++++++++ .../late_bound_through_alias.rs | 16 ++++++++++++++ .../late-bound-lifetimes/mismatched_arg_count.rs | 12 +++++++++++ .../mismatched_arg_count.stderr | 17 +++++++++++++++ 8 files changed, 130 insertions(+) create mode 100644 tests/ui/late-bound-lifetimes/auxiliary/upstream_alias.rs create mode 100644 tests/ui/late-bound-lifetimes/cross_crate_alias.rs create mode 100644 tests/ui/late-bound-lifetimes/downgraded_to_early_through_alias.rs create mode 100644 tests/ui/late-bound-lifetimes/issue-36381.rs create mode 100644 tests/ui/late-bound-lifetimes/issue-47511.rs create mode 100644 tests/ui/late-bound-lifetimes/late_bound_through_alias.rs create mode 100644 tests/ui/late-bound-lifetimes/mismatched_arg_count.rs create mode 100644 tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr (limited to 'tests/ui/late-bound-lifetimes') diff --git a/tests/ui/late-bound-lifetimes/auxiliary/upstream_alias.rs b/tests/ui/late-bound-lifetimes/auxiliary/upstream_alias.rs new file mode 100644 index 000000000..5b9dc0e43 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/auxiliary/upstream_alias.rs @@ -0,0 +1,5 @@ +pub trait Trait<'a> { + type Assoc; +} + +pub type Alias<'a, T> = >::Assoc; diff --git a/tests/ui/late-bound-lifetimes/cross_crate_alias.rs b/tests/ui/late-bound-lifetimes/cross_crate_alias.rs new file mode 100644 index 000000000..4154c2792 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/cross_crate_alias.rs @@ -0,0 +1,10 @@ +// aux-build:upstream_alias.rs +// check-pass + +extern crate upstream_alias; + +fn foo<'a, T: for<'b> upstream_alias::Trait<'b>>(_: upstream_alias::Alias<'a, T>) -> &'a () { + todo!() +} + +fn main() {} diff --git a/tests/ui/late-bound-lifetimes/downgraded_to_early_through_alias.rs b/tests/ui/late-bound-lifetimes/downgraded_to_early_through_alias.rs new file mode 100644 index 000000000..e56a34218 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/downgraded_to_early_through_alias.rs @@ -0,0 +1,24 @@ +// check-pass + +trait Gats<'a> { + type Assoc; + type Assoc2; +} + +trait Trait: for<'a> Gats<'a> { + fn foo<'a>(_: &mut >::Assoc) -> >::Assoc2; +} + +impl<'a> Gats<'a> for () { + type Assoc = &'a u32; + type Assoc2 = (); +} + +type GatsAssoc<'a, T> = >::Assoc; +type GatsAssoc2<'a, T> = >::Assoc2; + +impl Trait for () { + fn foo<'a>(_: &mut GatsAssoc<'a, Self>) -> GatsAssoc2<'a, Self> {} +} + +fn main() {} diff --git a/tests/ui/late-bound-lifetimes/issue-36381.rs b/tests/ui/late-bound-lifetimes/issue-36381.rs new file mode 100644 index 000000000..7db56f1dc --- /dev/null +++ b/tests/ui/late-bound-lifetimes/issue-36381.rs @@ -0,0 +1,25 @@ +// run-pass +// Regression test for #36381. The monomorphization collector was asserting that +// there are no projection types, but the `<&str as +// StreamOnce>::Position` projection contained a late-bound region, +// and we don't currently normalize in that case until the function is +// actually invoked. + +pub trait StreamOnce { + type Position; +} + +impl<'a> StreamOnce for &'a str { + type Position = usize; +} + +pub fn parser(_: F) { +} + +fn follow(_: &str) -> <&str as StreamOnce>::Position { + panic!() +} + +fn main() { + parser(follow); +} diff --git a/tests/ui/late-bound-lifetimes/issue-47511.rs b/tests/ui/late-bound-lifetimes/issue-47511.rs new file mode 100644 index 000000000..789443515 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/issue-47511.rs @@ -0,0 +1,21 @@ +// check-pass + +fn f(_: X) -> X { + unimplemented!() +} + +fn g<'a>(_: X<'a>) -> X<'a> { + unimplemented!() +} + +type X<'a> = <&'a () as Trait>::Value; + +trait Trait { + type Value; +} + +impl<'a> Trait for &'a () { + type Value = (); +} + +fn main() {} diff --git a/tests/ui/late-bound-lifetimes/late_bound_through_alias.rs b/tests/ui/late-bound-lifetimes/late_bound_through_alias.rs new file mode 100644 index 000000000..91839673c --- /dev/null +++ b/tests/ui/late-bound-lifetimes/late_bound_through_alias.rs @@ -0,0 +1,16 @@ +// check-pass + +fn f(_: X) -> X { + unimplemented!() +} + +fn g<'a>(_: X<'a>) -> X<'a> { + unimplemented!() +} + +type X<'a> = &'a (); + +fn main() { + let _: for<'a> fn(X<'a>) -> X<'a> = g; + let _: for<'a> fn(X<'a>) -> X<'a> = f; +} diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.rs b/tests/ui/late-bound-lifetimes/mismatched_arg_count.rs new file mode 100644 index 000000000..0b331e203 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.rs @@ -0,0 +1,12 @@ +// ensures that we don't ICE when there are too many args supplied to the alias. + +trait Trait<'a> { + type Assoc; +} + +type Alias<'a, T> = >::Assoc; + +fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} +//~^ error: this type alias takes 1 lifetime argument but 2 lifetime arguments were supplied + +fn main() {} diff --git a/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr new file mode 100644 index 000000000..3704d9bb9 --- /dev/null +++ b/tests/ui/late-bound-lifetimes/mismatched_arg_count.stderr @@ -0,0 +1,17 @@ +error[E0107]: this type alias takes 1 lifetime argument but 2 lifetime arguments were supplied + --> $DIR/mismatched_arg_count.rs:9:29 + | +LL | fn bar<'a, T: Trait<'a>>(_: Alias<'a, 'a, T>) {} + | ^^^^^ -- help: remove this lifetime argument + | | + | expected 1 lifetime argument + | +note: type alias defined here, with 1 lifetime parameter: `'a` + --> $DIR/mismatched_arg_count.rs:7:6 + | +LL | type Alias<'a, T> = >::Assoc; + | ^^^^^ -- + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0107`. -- cgit v1.2.3