From 631cd5845e8de329d0e227aaa707d7ea228b8f8f Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:20:29 +0200 Subject: Merging upstream version 1.70.0+dfsg1. Signed-off-by: Daniel Baumann --- tests/ui/ufcs/ufcs-partially-resolved.rs | 44 +++---- tests/ui/ufcs/ufcs-partially-resolved.stderr | 190 +++++++++++++++++---------- tests/ui/ufcs/ufcs-polymorphic-paths.rs | 154 ++++++++++++++++++++++ 3 files changed, 293 insertions(+), 95 deletions(-) create mode 100644 tests/ui/ufcs/ufcs-polymorphic-paths.rs (limited to 'tests/ui/ufcs') diff --git a/tests/ui/ufcs/ufcs-partially-resolved.rs b/tests/ui/ufcs/ufcs-partially-resolved.rs index e6470aa6d..712668728 100644 --- a/tests/ui/ufcs/ufcs-partially-resolved.rs +++ b/tests/ui/ufcs/ufcs-partially-resolved.rs @@ -17,37 +17,37 @@ type A = u32; fn main() { let _: ::N; //~ ERROR cannot find associated type `N` in trait `Tr` - let _: ::N; //~ ERROR cannot find associated type `N` in enum `E` - let _: ::N; //~ ERROR cannot find associated type `N` in `A` + let _: ::N; //~ ERROR expected trait, found enum `E` + let _: ::N; //~ ERROR expected trait, found type alias `A` ::N; //~ ERROR cannot find method or associated constant `N` in trait `Tr` - ::N; //~ ERROR cannot find method or associated constant `N` in enum `E` - ::N; //~ ERROR cannot find method or associated constant `N` in `A` + ::N; //~ ERROR expected trait, found enum `E` + ::N; //~ ERROR expected trait, found type alias `A` let _: ::Y; // OK - let _: ::Y; //~ ERROR expected associated type, found variant `E::Y` + let _: ::Y; //~ ERROR expected trait, found enum `E` ::Y; // OK - ::Y; //~ ERROR expected method or associated constant, found unit variant `E::Y` + ::Y; //~ ERROR expected trait, found enum `E` let _: ::N::NN; //~ ERROR cannot find associated type `N` in trait `Tr` - let _: ::N::NN; //~ ERROR cannot find associated type `N` in enum `E` - let _: ::N::NN; //~ ERROR cannot find associated type `N` in `A` + let _: ::N::NN; //~ ERROR expected trait, found enum `E` + let _: ::N::NN; //~ ERROR expected trait, found type alias `A` ::N::NN; //~ ERROR cannot find associated type `N` in trait `Tr` - ::N::NN; //~ ERROR cannot find associated type `N` in enum `E` - ::N::NN; //~ ERROR cannot find associated type `N` in `A` + ::N::NN; //~ ERROR expected trait, found enum `E` + ::N::NN; //~ ERROR expected trait, found type alias `A` let _: ::Y::NN; //~ ERROR ambiguous associated type - let _: ::Y::NN; //~ ERROR expected associated type, found variant `E::Y` + let _: ::Y::NN; //~ ERROR expected trait, found enum `E` ::Y::NN; //~ ERROR no associated item named `NN` found for type `u16` - ::Y::NN; //~ ERROR expected associated type, found variant `E::Y` + ::Y::NN; //~ ERROR expected trait, found enum `E` - let _: ::NN; //~ ERROR cannot find associated type `NN` in `Tr::N` - let _: ::NN; //~ ERROR cannot find associated type `NN` in `E::N` - let _: ::NN; //~ ERROR cannot find associated type `NN` in `A::N` - ::NN; //~ ERROR cannot find method or associated constant `NN` in `Tr::N` - ::NN; //~ ERROR cannot find method or associated constant `NN` in `E::N` - ::NN; //~ ERROR cannot find method or associated constant `NN` in `A::N` - let _: ::NN; //~ ERROR cannot find associated type `NN` in `Tr::Y` - let _: ::NN; //~ ERROR failed to resolve: `Y` is a variant, not a module - ::NN; //~ ERROR cannot find method or associated constant `NN` in `Tr::Y` - ::NN; //~ ERROR failed to resolve: `Y` is a variant, not a module + let _: ::NN; //~ ERROR cannot find trait `N` in trait `Tr` + let _: ::NN; //~ ERROR cannot find trait `N` in enum `E` + let _: ::NN; //~ ERROR cannot find trait `N` in `A` + ::NN; //~ ERROR cannot find trait `N` in trait `Tr` + ::NN; //~ ERROR cannot find trait `N` in enum `E` + ::NN; //~ ERROR cannot find trait `N` in `A` + let _: ::NN; //~ ERROR expected trait, found associated type `Tr::Y + let _: ::NN; //~ ERROR expected trait, found variant `E::Y` + ::NN; //~ ERROR expected trait, found associated type `Tr::Y` + ::NN; //~ ERROR expected trait, found variant `E::Y` let _: ::Z; //~ ERROR expected associated type, found associated function `Dr::Z` ::X; //~ ERROR expected method or associated constant, found associated type `Dr::X` diff --git a/tests/ui/ufcs/ufcs-partially-resolved.stderr b/tests/ui/ufcs/ufcs-partially-resolved.stderr index 72fccea8a..eef55c8dc 100644 --- a/tests/ui/ufcs/ufcs-partially-resolved.stderr +++ b/tests/ui/ufcs/ufcs-partially-resolved.stderr @@ -1,15 +1,3 @@ -error[E0433]: failed to resolve: `Y` is a variant, not a module - --> $DIR/ufcs-partially-resolved.rs:48:22 - | -LL | let _: ::NN; - | ^ `Y` is a variant, not a module - -error[E0433]: failed to resolve: `Y` is a variant, not a module - --> $DIR/ufcs-partially-resolved.rs:50:15 - | -LL | ::NN; - | ^ `Y` is a variant, not a module - error[E0576]: cannot find associated type `N` in trait `Tr` --> $DIR/ufcs-partially-resolved.rs:19:24 | @@ -19,17 +7,25 @@ LL | type Y = u16; LL | let _: ::N; | ^ help: an associated type with a similar name exists: `Y` -error[E0576]: cannot find associated type `N` in enum `E` - --> $DIR/ufcs-partially-resolved.rs:20:23 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:20:19 | LL | let _: ::N; - | ^ not found in `E` + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0576]: cannot find associated type `N` in `A` - --> $DIR/ufcs-partially-resolved.rs:21:23 +error[E0404]: expected trait, found type alias `A` + --> $DIR/ufcs-partially-resolved.rs:21:19 | LL | let _: ::N; - | ^ not found in `A` + | ^ type aliases cannot be used as traits + | +help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias + | +LL | trait A = u32; + | error[E0576]: cannot find method or associated constant `N` in trait `Tr` --> $DIR/ufcs-partially-resolved.rs:22:17 @@ -40,29 +36,43 @@ LL | fn Y() {} LL | ::N; | ^ help: an associated function with a similar name exists: `Y` -error[E0576]: cannot find method or associated constant `N` in enum `E` - --> $DIR/ufcs-partially-resolved.rs:23:16 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:23:12 | LL | ::N; - | ^ not found in `E` + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0576]: cannot find method or associated constant `N` in `A` - --> $DIR/ufcs-partially-resolved.rs:24:16 +error[E0404]: expected trait, found type alias `A` + --> $DIR/ufcs-partially-resolved.rs:24:12 | LL | ::N; - | ^ not found in `A` + | ^ type aliases cannot be used as traits + | +help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias + | +LL | trait A = u32; + | -error[E0575]: expected associated type, found variant `E::Y` - --> $DIR/ufcs-partially-resolved.rs:26:12 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:26:19 | LL | let _: ::Y; - | ^^^^^^^^^^^^ not a associated type + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0575]: expected method or associated constant, found unit variant `E::Y` - --> $DIR/ufcs-partially-resolved.rs:28:5 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:28:12 | LL | ::Y; - | ^^^^^^^^^^^^ not a method or associated constant + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here error[E0576]: cannot find associated type `N` in trait `Tr` --> $DIR/ufcs-partially-resolved.rs:30:24 @@ -73,17 +83,25 @@ LL | type Y = u16; LL | let _: ::N::NN; | ^ help: an associated type with a similar name exists: `Y` -error[E0576]: cannot find associated type `N` in enum `E` - --> $DIR/ufcs-partially-resolved.rs:31:23 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:31:19 | LL | let _: ::N::NN; - | ^ not found in `E` + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0576]: cannot find associated type `N` in `A` - --> $DIR/ufcs-partially-resolved.rs:32:23 +error[E0404]: expected trait, found type alias `A` + --> $DIR/ufcs-partially-resolved.rs:32:19 | LL | let _: ::N::NN; - | ^ not found in `A` + | ^ type aliases cannot be used as traits + | +help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias + | +LL | trait A = u32; + | error[E0576]: cannot find associated type `N` in trait `Tr` --> $DIR/ufcs-partially-resolved.rs:33:17 @@ -94,77 +112,103 @@ LL | type Y = u16; LL | ::N::NN; | ^ help: an associated type with a similar name exists: `Y` -error[E0576]: cannot find associated type `N` in enum `E` - --> $DIR/ufcs-partially-resolved.rs:34:16 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:34:12 | LL | ::N::NN; - | ^ not found in `E` + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0576]: cannot find associated type `N` in `A` - --> $DIR/ufcs-partially-resolved.rs:35:16 +error[E0404]: expected trait, found type alias `A` + --> $DIR/ufcs-partially-resolved.rs:35:12 | LL | ::N::NN; - | ^ not found in `A` + | ^ type aliases cannot be used as traits + | +help: you might have meant to use `#![feature(trait_alias)]` instead of a `type` alias + | +LL | trait A = u32; + | -error[E0575]: expected associated type, found variant `E::Y` - --> $DIR/ufcs-partially-resolved.rs:37:12 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:37:19 | LL | let _: ::Y::NN; - | ^^^^^^^^^^^^^^^^ not a associated type + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0575]: expected associated type, found variant `E::Y` - --> $DIR/ufcs-partially-resolved.rs:39:5 +error[E0404]: expected trait, found enum `E` + --> $DIR/ufcs-partially-resolved.rs:39:12 | LL | ::Y::NN; - | ^^^^^^^^^^^^^^^^ not a associated type + | ^ help: a trait with a similar name exists: `Eq` + --> $SRC_DIR/core/src/cmp.rs:LL:COL + | + = note: similarly named trait `Eq` defined here -error[E0576]: cannot find associated type `NN` in `Tr::N` - --> $DIR/ufcs-partially-resolved.rs:41:27 +error[E0405]: cannot find trait `N` in trait `Tr` + --> $DIR/ufcs-partially-resolved.rs:41:23 | LL | let _: ::NN; - | ^^ not found in `Tr::N` + | ^ not found in `Tr` -error[E0576]: cannot find associated type `NN` in `E::N` - --> $DIR/ufcs-partially-resolved.rs:42:26 +error[E0405]: cannot find trait `N` in enum `E` + --> $DIR/ufcs-partially-resolved.rs:42:22 | LL | let _: ::NN; - | ^^ not found in `E::N` + | ^ not found in `E` -error[E0576]: cannot find associated type `NN` in `A::N` - --> $DIR/ufcs-partially-resolved.rs:43:26 +error[E0405]: cannot find trait `N` in `A` + --> $DIR/ufcs-partially-resolved.rs:43:22 | LL | let _: ::NN; - | ^^ not found in `A::N` + | ^ not found in `A` -error[E0576]: cannot find method or associated constant `NN` in `Tr::N` - --> $DIR/ufcs-partially-resolved.rs:44:20 +error[E0405]: cannot find trait `N` in trait `Tr` + --> $DIR/ufcs-partially-resolved.rs:44:16 | LL | ::NN; - | ^^ not found in `Tr::N` + | ^ not found in `Tr` -error[E0576]: cannot find method or associated constant `NN` in `E::N` - --> $DIR/ufcs-partially-resolved.rs:45:19 +error[E0405]: cannot find trait `N` in enum `E` + --> $DIR/ufcs-partially-resolved.rs:45:15 | LL | ::NN; - | ^^ not found in `E::N` + | ^ not found in `E` -error[E0576]: cannot find method or associated constant `NN` in `A::N` - --> $DIR/ufcs-partially-resolved.rs:46:19 +error[E0405]: cannot find trait `N` in `A` + --> $DIR/ufcs-partially-resolved.rs:46:15 | LL | ::NN; - | ^^ not found in `A::N` + | ^ not found in `A` -error[E0576]: cannot find associated type `NN` in `Tr::Y` - --> $DIR/ufcs-partially-resolved.rs:47:27 +error[E0404]: expected trait, found associated type `Tr::Y` + --> $DIR/ufcs-partially-resolved.rs:47:19 | LL | let _: ::NN; - | ^^ not found in `Tr::Y` + | ^^^^^ not a trait + +error[E0404]: expected trait, found variant `E::Y` + --> $DIR/ufcs-partially-resolved.rs:48:19 + | +LL | let _: ::NN; + | ^^^^ not a trait -error[E0576]: cannot find method or associated constant `NN` in `Tr::Y` - --> $DIR/ufcs-partially-resolved.rs:49:20 +error[E0404]: expected trait, found associated type `Tr::Y` + --> $DIR/ufcs-partially-resolved.rs:49:12 | LL | ::NN; - | ^^ not found in `Tr::Y` + | ^^^^^ not a trait + +error[E0404]: expected trait, found variant `E::Y` + --> $DIR/ufcs-partially-resolved.rs:50:12 + | +LL | ::NN; + | ^^^^ not a trait error[E0575]: expected associated type, found associated function `Dr::Z` --> $DIR/ufcs-partially-resolved.rs:52:12 @@ -226,5 +270,5 @@ LL | ::X::N; error: aborting due to 32 previous errors -Some errors have detailed explanations: E0223, E0433, E0575, E0576, E0599. +Some errors have detailed explanations: E0223, E0404, E0405, E0575, E0576, E0599. For more information about an error, try `rustc --explain E0223`. diff --git a/tests/ui/ufcs/ufcs-polymorphic-paths.rs b/tests/ui/ufcs/ufcs-polymorphic-paths.rs new file mode 100644 index 000000000..a14ebd6a4 --- /dev/null +++ b/tests/ui/ufcs/ufcs-polymorphic-paths.rs @@ -0,0 +1,154 @@ +// run-pass + +use std::borrow::{Cow, ToOwned}; +use std::default::Default; +use std::iter::FromIterator; +use std::ops::Add; +use std::option::IntoIter as OptionIter; + +pub struct XorShiftRng; +use XorShiftRng as DummyRng; +impl Rng for XorShiftRng {} +pub trait Rng {} +pub trait Rand: Default + Sized { + fn rand(_rng: &mut R) -> Self { Default::default() } +} +impl Rand for i32 { } + +pub trait IntoCow<'a, B: ?Sized> where B: ToOwned { + fn into_cow(self) -> Cow<'a, B>; +} + +impl<'a> IntoCow<'a, str> for String { + fn into_cow(self) -> Cow<'a, str> { + Cow::Owned(self) + } +} + +#[derive(PartialEq, Eq)] +struct Newt(T); + +fn id(x: T) -> T { x } +fn eq(a: T, b: T) -> bool { a == b } +fn u8_as_i8(x: u8) -> i8 { x as i8 } +fn odd(x: usize) -> bool { x % 2 == 1 } +fn dummy_rng() -> DummyRng { XorShiftRng } + +trait Size: Sized { + fn size() -> usize { std::mem::size_of::() } +} +impl Size for T {} + +#[derive(PartialEq, Eq)] +struct BitVec; + +impl BitVec { + fn from_fn(_: usize, _: F) -> BitVec where F: FnMut(usize) -> bool { + BitVec + } +} + +#[derive(PartialEq, Eq)] +struct Foo(T); + +impl Foo { + fn map_in_place(self, mut f: F) -> Foo where F: FnMut(T) -> U { + Foo(f(self.0)) + } + +} + +macro_rules! tests { + ($($expr:expr, $ty:ty, ($($test:expr),*);)+) => (pub fn main() {$({ + const C: $ty = $expr; + static S: $ty = $expr; + assert!(eq(C($($test),*), $expr($($test),*))); + assert!(eq(S($($test),*), $expr($($test),*))); + assert!(eq(C($($test),*), S($($test),*))); + })+}) +} + +tests! { + // Free function. + id, fn(i32) -> i32, (5); + id::, fn(i32) -> i32, (5); + + // Enum variant constructor. + Some, fn(i32) -> Option, (5); + Some::, fn(i32) -> Option, (5); + + // Tuple struct constructor. + Newt, fn(i32) -> Newt, (5); + Newt::, fn(i32) -> Newt, (5); + + // Inherent static methods. + Vec::new, fn() -> Vec<()>, (); + Vec::<()>::new, fn() -> Vec<()>, (); + >::new, fn() -> Vec<()>, (); + Vec::with_capacity, fn(usize) -> Vec<()>, (5); + Vec::<()>::with_capacity, fn(usize) -> Vec<()>, (5); + >::with_capacity, fn(usize) -> Vec<()>, (5); + BitVec::from_fn, fn(usize, fn(usize) -> bool) -> BitVec, (5, odd); + BitVec::from_fn:: bool>, fn(usize, fn(usize) -> bool) -> BitVec, (5, odd); + + // Inherent non-static method. + Foo::map_in_place, fn(Foo, fn(u8) -> i8) -> Foo, (Foo(b'f'), u8_as_i8); + Foo::map_in_place:: i8>, fn(Foo, fn(u8) -> i8) -> Foo, + (Foo(b'f'), u8_as_i8); + Foo::::map_in_place, fn(Foo, fn(u8) -> i8) -> Foo + , (Foo(b'f'), u8_as_i8); + Foo::::map_in_place:: i8>, fn(Foo, fn(u8) -> i8) -> Foo + , (Foo(b'f'), u8_as_i8); + + // Trait static methods. + bool::size, fn() -> usize, (); + ::size, fn() -> usize, (); + ::size, fn() -> usize, (); + + Default::default, fn() -> i32, (); + i32::default, fn() -> i32, (); + ::default, fn() -> i32, (); + ::default, fn() -> i32, (); + + Rand::rand, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + i32::rand, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + ::rand, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + ::rand, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + Rand::rand::, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + i32::rand::, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + ::rand::, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + ::rand::, fn(&mut DummyRng) -> i32, (&mut dummy_rng()); + + // Trait non-static methods. + Clone::clone, fn(&i32) -> i32, (&5); + i32::clone, fn(&i32) -> i32, (&5); + ::clone, fn(&i32) -> i32, (&5); + ::clone, fn(&i32) -> i32, (&5); + + FromIterator::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); + Vec::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); + >::from_iter, fn(OptionIter) -> Vec, (Some(5).into_iter()); + as FromIterator<_>>::from_iter, fn(OptionIter) -> Vec, + (Some(5).into_iter()); + as FromIterator<_>>::from_iter, fn(OptionIter) -> Vec, + (Some(5).into_iter()); + FromIterator::from_iter::>, fn(OptionIter) -> Vec, + (Some(5).into_iter()); + as FromIterator<_>>::from_iter::>, fn(OptionIter) -> Vec, + (Some(5).into_iter()); + + Add::add, fn(i32, i32) -> i32, (5, 6); + i32::add, fn(i32, i32) -> i32, (5, 6); + ::add, fn(i32, i32) -> i32, (5, 6); + >::add, fn(i32, i32) -> i32, (5, 6); + >::add, fn(i32, i32) -> i32, (5, 6); + + String::into_cow, fn(String) -> Cow<'static, str>, + ("foo".to_string()); + ::into_cow, fn(String) -> Cow<'static, str>, + ("foo".to_string()); + >::into_cow, fn(String) -> Cow<'static, str>, + ("foo".to_string()); + >::into_cow, fn(String) -> Cow<'static, str>, + ("foo".to_string()); +} -- cgit v1.2.3