Skip to content

Commit 4137901

Browse files
committed
Auto merge of #61203 - memoryruins:bare_trait_objects, r=Centril
Warn on bare_trait_objects by default The `bare_trait_objects` lint is set to `warn` by default. Most ui tests have been updated to use `dyn` to avoid creating noise in stderr files. r? @Centril cc #54910
2 parents 37d001e + 83660b6 commit 4137901

File tree

752 files changed

+2178
-2132
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

752 files changed

+2178
-2132
lines changed

src/librustc/lint/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ declare_lint! {
255255

256256
declare_lint! {
257257
pub BARE_TRAIT_OBJECTS,
258-
Allow,
258+
Warn,
259259
"suggest using `dyn Trait` for trait objects"
260260
}
261261

src/libstd/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ pub trait Error: Debug + Display {
9494
/// "I'm the superhero of errors"
9595
/// }
9696
///
97-
/// fn cause(&self) -> Option<&Error> {
97+
/// fn cause(&self) -> Option<&dyn Error> {
9898
/// Some(&self.side)
9999
/// }
100100
/// }
@@ -244,7 +244,7 @@ impl<'a, E: Error + 'a> From<E> for Box<dyn Error + 'a> {
244244
///
245245
/// let an_error = AnError;
246246
/// assert!(0 == mem::size_of_val(&an_error));
247-
/// let a_boxed_error = Box::<Error>::from(an_error);
247+
/// let a_boxed_error = Box::<dyn Error>::from(an_error);
248248
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
249249
/// ```
250250
fn from(err: E) -> Box<dyn Error + 'a> {
@@ -287,7 +287,7 @@ impl<'a, E: Error + Send + Sync + 'a> From<E> for Box<dyn Error + Send + Sync +
287287
///
288288
/// let an_error = AnError;
289289
/// assert!(0 == mem::size_of_val(&an_error));
290-
/// let a_boxed_error = Box::<Error + Send + Sync>::from(an_error);
290+
/// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(an_error);
291291
/// assert!(
292292
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
293293
/// ```
@@ -309,7 +309,7 @@ impl From<String> for Box<dyn Error + Send + Sync> {
309309
/// use std::mem;
310310
///
311311
/// let a_string_error = "a string error".to_string();
312-
/// let a_boxed_error = Box::<Error + Send + Sync>::from(a_string_error);
312+
/// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_string_error);
313313
/// assert!(
314314
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
315315
/// ```
@@ -344,7 +344,7 @@ impl From<String> for Box<dyn Error> {
344344
/// use std::mem;
345345
///
346346
/// let a_string_error = "a string error".to_string();
347-
/// let a_boxed_error = Box::<Error>::from(a_string_error);
347+
/// let a_boxed_error = Box::<dyn Error>::from(a_string_error);
348348
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
349349
/// ```
350350
fn from(str_err: String) -> Box<dyn Error> {
@@ -367,7 +367,7 @@ impl<'a> From<&str> for Box<dyn Error + Send + Sync + 'a> {
367367
/// use std::mem;
368368
///
369369
/// let a_str_error = "a str error";
370-
/// let a_boxed_error = Box::<Error + Send + Sync>::from(a_str_error);
370+
/// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_str_error);
371371
/// assert!(
372372
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
373373
/// ```
@@ -389,7 +389,7 @@ impl From<&str> for Box<dyn Error> {
389389
/// use std::mem;
390390
///
391391
/// let a_str_error = "a str error";
392-
/// let a_boxed_error = Box::<Error>::from(a_str_error);
392+
/// let a_boxed_error = Box::<dyn Error>::from(a_str_error);
393393
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
394394
/// ```
395395
fn from(err: &str) -> Box<dyn Error> {
@@ -412,7 +412,7 @@ impl<'a, 'b> From<Cow<'b, str>> for Box<dyn Error + Send + Sync + 'a> {
412412
/// use std::borrow::Cow;
413413
///
414414
/// let a_cow_str_error = Cow::from("a str error");
415-
/// let a_boxed_error = Box::<Error + Send + Sync>::from(a_cow_str_error);
415+
/// let a_boxed_error = Box::<dyn Error + Send + Sync>::from(a_cow_str_error);
416416
/// assert!(
417417
/// mem::size_of::<Box<dyn Error + Send + Sync>>() == mem::size_of_val(&a_boxed_error))
418418
/// ```
@@ -436,7 +436,7 @@ impl<'a> From<Cow<'a, str>> for Box<dyn Error> {
436436
/// use std::borrow::Cow;
437437
///
438438
/// let a_cow_str_error = Cow::from("a str error");
439-
/// let a_boxed_error = Box::<Error>::from(a_cow_str_error);
439+
/// let a_boxed_error = Box::<dyn Error>::from(a_cow_str_error);
440440
/// assert!(mem::size_of::<Box<dyn Error>>() == mem::size_of_val(&a_boxed_error))
441441
/// ```
442442
fn from(err: Cow<'a, str>) -> Box<dyn Error> {

src/libstd/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1976,7 +1976,7 @@ pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> io::Result<()> {
19761976
/// use std::path::Path;
19771977
///
19781978
/// // one possible implementation of walking a directory only visiting files
1979-
/// fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> {
1979+
/// fn visit_dirs(dir: &Path, cb: &dyn Fn(&DirEntry)) -> io::Result<()> {
19801980
/// if dir.is_dir() {
19811981
/// for entry in fs::read_dir(dir)? {
19821982
/// let entry = entry?;

src/test/compile-fail/issue-23595-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::ops::{Index};
55
trait Hierarchy {
66
type Value;
77
type ChildKey;
8-
type Children = Index<Self::ChildKey, Output=Hierarchy>;
8+
type Children = dyn Index<Self::ChildKey, Output=dyn Hierarchy>;
99
//~^ ERROR: the value of the associated types `Value` (from the trait `Hierarchy`), `ChildKey`
1010

1111
fn data(&self) -> Option<(Self::Value, Self::Children)>;

src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn make_x() -> P<Expr> {
6262
/// Iterate over exprs of depth up to `depth`. The goal is to explore all "interesting"
6363
/// combinations of expression nesting. For example, we explore combinations using `if`, but not
6464
/// `while` or `match`, since those should print and parse in much the same way as `if`.
65-
fn iter_exprs(depth: usize, f: &mut FnMut(P<Expr>)) {
65+
fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
6666
if depth == 0 {
6767
f(make_x());
6868
return;

src/test/run-pass/alignment-gep-tup-like-1.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ impl<A:Clone> Invokable<A> for Invoker<A> {
2222
}
2323
}
2424

25-
fn f<A:Clone + 'static>(a: A, b: u16) -> Box<Invokable<A>+'static> {
25+
fn f<A:Clone + 'static>(a: A, b: u16) -> Box<dyn Invokable<A>+'static> {
2626
box Invoker {
2727
a: a,
2828
b: b,
29-
} as (Box<Invokable<A>+'static>)
29+
} as (Box<dyn Invokable<A>+'static>)
3030
}
3131

3232
pub fn main() {

src/test/run-pass/associated-types/associated-types-doubleendediterator-object.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// run-pass
22
#![feature(box_syntax)]
33

4-
fn pairwise_sub(mut t: Box<DoubleEndedIterator<Item=isize>>) -> isize {
4+
fn pairwise_sub(mut t: Box<dyn DoubleEndedIterator<Item=isize>>) -> isize {
55
let mut result = 0;
66
loop {
77
let front = t.next();

src/test/run-pass/associated-types/associated-types-eq-obj.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ impl Foo for char {
1515
fn boo(&self) -> Bar { Bar }
1616
}
1717

18-
fn baz(x: &Foo<A=Bar>) -> Bar {
18+
fn baz(x: &dyn Foo<A=Bar>) -> Bar {
1919
x.boo()
2020
}
2121

src/test/run-pass/associated-types/associated-types-projection-in-object-type.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,20 @@ pub trait Subscriber {
1919

2020
pub trait Publisher<'a> {
2121
type Output;
22-
fn subscribe(&mut self, _: Box<Subscriber<Input=Self::Output> + 'a>);
22+
fn subscribe(&mut self, _: Box<dyn Subscriber<Input=Self::Output> + 'a>);
2323
}
2424

2525
pub trait Processor<'a> : Subscriber + Publisher<'a> { }
2626

2727
impl<'a, P> Processor<'a> for P where P : Subscriber + Publisher<'a> { }
2828

2929
struct MyStruct<'a> {
30-
sub: Box<Subscriber<Input=u64> + 'a>
30+
sub: Box<dyn Subscriber<Input=u64> + 'a>
3131
}
3232

3333
impl<'a> Publisher<'a> for MyStruct<'a> {
3434
type Output = u64;
35-
fn subscribe(&mut self, t : Box<Subscriber<Input=u64> + 'a>) {
35+
fn subscribe(&mut self, t : Box<dyn Subscriber<Input=u64> + 'a>) {
3636
self.sub = t;
3737
}
3838
}

src/test/run-pass/autoref-autoderef/autoderef-method-on-trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ impl double for usize {
1111
}
1212

1313
pub fn main() {
14-
let x: Box<_> = box (box 3usize as Box<double>);
14+
let x: Box<_> = box (box 3usize as Box<dyn double>);
1515
assert_eq!(x.double(), 6);
1616
}

0 commit comments

Comments
 (0)