Description
I have found that constructing a struct which implements a Supertrait, and then calling one of the trait methods of that Supertrait via the subtrait leads to a warning about trait objects without an explicit dyn
being deprecated. See the following minimal example
pub trait Pin: Configure {}
pub trait Configure {
fn make_output(&self);
}
pub struct MyPin {}
impl Configure for MyPin {
fn make_output(&self) {}
}
impl Pin for MyPin {}
fn main() {
let pin = &mut MyPin {};
//Configure::make_output(pin); //no warning
Pin::make_output(pin); //prints a warning
}
I expected this to compile without warning
Instead, I get the following output:
warning: trait objects without an explicit `dyn` are deprecated
--> src/main.rs:20:5
|
20 | hil::Pin::make_output(pin); //prints a warning
| ^^^^^^^^ help: use `dyn`: `<dyn hil::Pin>`
|
= note: `#[warn(bare_trait_objects)]` on by default
It is very surprising to me that whether I get a warning is dependent on whether or not I call the method directly via the Supertrait rather than via the subtrait. I would have expected those to compile equivalent code.
(This minimal reproduction is based off of encountering this error in a number of places in Tock when upgrading to the latest nightly.)
Meta
This happens on current nightly (2021-03-21) but not on a 2 month old nightly (2021-01-07), or on current stable (1.50.0).
Playground link with the warning: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=c4bb2774141c86d7af6971e1876a203c