Rollup merge of #141957 - ferrocene:lw/missing-dyn-kw2, r=compiler-errors

Add missing `dyn` keywords to tests that do not test for them Part 2

Some more tests that were found
This commit is contained in:
Matthias Krüger 2025-06-03 21:53:39 +02:00 committed by GitHub
commit a2b6f14af3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
15 changed files with 26 additions and 31 deletions

View File

@ -11,6 +11,6 @@ mod inner {
}
pub fn foo() {
let a = &1isize as &inner::Trait;
let a = &1isize as &dyn inner::Trait;
a.f();
}

View File

@ -16,7 +16,7 @@ pub mod testtypes {
TypeId::of::<FooFnPtr>(),
TypeId::of::<FooNil>(),
TypeId::of::<FooTuple>(),
TypeId::of::<FooTrait>(),
TypeId::of::<dyn FooTrait>(),
TypeId::of::<FooStruct>(),
TypeId::of::<FooEnum>()
]

View File

@ -4,9 +4,9 @@ pub trait Foo<'a, T> {
fn foo(&'a self) -> T;
}
pub fn foo<'a, T>(x: &'a Foo<'a, T>) -> T {
let x: &'a Foo<T> = x;
// ^ the lifetime parameter of Foo is left to be inferred.
pub fn foo<'a, T>(x: &'a dyn Foo<'a, T>) -> T {
let x: &'a dyn Foo<T> = x;
// ^ the lifetime parameter of Foo is left to be inferred.
x.foo()
// ^ encoding this method call in metadata triggers an ICE.
}

View File

@ -6,8 +6,8 @@ pub trait i<T>
fn dummy(&self, t: T) -> T { panic!() }
}
pub fn f<T>() -> Box<i<T>+'static> {
pub fn f<T>() -> Box<dyn i<T>+'static> {
impl<T> i<T> for () { }
Box::new(()) as Box<i<T>+'static>
Box::new(()) as Box<dyn i<T>+'static>
}

View File

@ -7,4 +7,4 @@ pub trait Trait {
type Issue25467BarT;
}
pub type Object = Option<Box<Trait<Issue25467FooT=(),Issue25467BarT=()>>>;
pub type Object = Option<Box<dyn Trait<Issue25467FooT=(),Issue25467BarT=()>>>;

View File

@ -9,7 +9,7 @@ impl Future for u32 {
type Error = Box<()>;
}
fn foo() -> Box<Future<Item=(), Error=Box<()>>> {
fn foo() -> Box<dyn Future<Item=(), Error=Box<()>>> {
Box::new(0u32)
}

View File

@ -2,7 +2,7 @@
#[inline(never)]
pub fn foo<T>() {
let _: Box<SomeTrait> = Box::new(SomeTraitImpl);
let _: Box<dyn SomeTrait> = Box::new(SomeTraitImpl);
}
pub fn bar() {

View File

@ -8,9 +8,9 @@ trait A {
struct B;
impl A for B {}
fn bar<T>(_: &mut A, _: &T) {}
fn bar<T>(_: &mut dyn A, _: &T) {}
fn foo<T>(t: &T) {
let mut b = B;
bar(&mut b as &mut A, t)
bar(&mut b as &mut dyn A, t)
}

View File

@ -4,7 +4,7 @@ trait Trait<T> {
fn foo(_: T) {}
}
pub struct Foo<T = Box<Trait<DefaultFoo>>>; //~ ERROR cycle detected
pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>; //~ ERROR cycle detected
//~^ ERROR `T` is never used
type DefaultFoo = Foo;

View File

@ -1,8 +1,8 @@
error[E0391]: cycle detected when computing type of `Foo::T`
--> $DIR/issue-34373.rs:7:30
--> $DIR/issue-34373.rs:7:34
|
LL | pub struct Foo<T = Box<Trait<DefaultFoo>>>;
| ^^^^^^^^^^
LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
| ^^^^^^^^^^
|
note: ...which requires expanding type alias `DefaultFoo`...
--> $DIR/issue-34373.rs:9:19
@ -13,15 +13,15 @@ LL | type DefaultFoo = Foo;
note: cycle used when checking that `Foo` is well-formed
--> $DIR/issue-34373.rs:7:1
|
LL | pub struct Foo<T = Box<Trait<DefaultFoo>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
error[E0392]: type parameter `T` is never used
--> $DIR/issue-34373.rs:7:16
|
LL | pub struct Foo<T = Box<Trait<DefaultFoo>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ unused type parameter
LL | pub struct Foo<T = Box<dyn Trait<DefaultFoo>>>;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unused type parameter
|
= help: consider removing `T`, referring to it in a field, or using a marker such as `PhantomData`
= help: if you intended `T` to be a const parameter, use `const T: /* Type */` instead

View File

@ -3,9 +3,8 @@
// Helper for testing that we get suitable warnings when lifetime
// bound change will cause breakage.
pub fn just_ref(x: &Fn()) {
}
pub fn just_ref(x: &dyn Fn()) {}
pub fn ref_obj(x: &Box<Fn()>) {
pub fn ref_obj(x: &Box<dyn Fn()>) {
// this will change to &Box<Fn()+'static>...
}

View File

@ -1,7 +1,5 @@
//@ check-pass
#![allow(bare_trait_objects)]
type A = Box<(Fn(u8) -> u8) + 'static + Send + Sync>; // OK (but see #39318)
type A = Box<dyn (Fn(u8) -> u8) + 'static + Send + Sync>; // OK (but see #39318)
fn main() {}

View File

@ -1,9 +1,7 @@
//@ check-pass
#![allow(bare_trait_objects)]
use std::fmt::Debug;
fn main() {
let x: Box<Debug+> = Box::new(3) as Box<Debug+>; // Trailing `+` is OK
let x: Box<dyn Debug+> = Box::new(3) as Box<dyn Debug+>; // Trailing `+` is OK
}

View File

@ -10,7 +10,7 @@ trait Foo {
// Here the receiver and return value all have the same lifetime,
// so no error results.
fn borrowed_receiver_same_lifetime<'a>(x: &'a Foo) -> &'a () {
fn borrowed_receiver_same_lifetime<'a>(x: &'a dyn Foo) -> &'a () {
x.borrowed()
}

View File

@ -10,7 +10,7 @@ trait Foo {
// Borrowed receiver with two distinct lifetimes, but we know that
// 'b:'a, hence &'a () is permitted.
fn borrowed_receiver_related_lifetimes<'a,'b>(x: &'a (Foo+'b)) -> &'a () {
fn borrowed_receiver_related_lifetimes<'a,'b>(x: &'a (dyn Foo+'b)) -> &'a () {
x.borrowed()
}