diff options
| author | bors <bors@rust-lang.org> | 2021-03-18 05:27:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-03-18 05:27:26 +0000 |
| commit | 2aafe452b898aa3fdfb2c5a1a649ed0922e1401d (patch) | |
| tree | b7c27651086eb8ec2358fdee1b6795d71c191c04 /src | |
| parent | 81c1d7a1506e5f4bcc5f12fb49f3b6e9bb87c605 (diff) | |
| parent | b48530bf8b30c20a75f5bb7c2021a28c0ae40413 (diff) | |
| download | rust-2aafe452b898aa3fdfb2c5a1a649ed0922e1401d.tar.gz rust-2aafe452b898aa3fdfb2c5a1a649ed0922e1401d.zip | |
Auto merge of #82868 - petrochenkov:bto, r=estebank
Report missing cases of `bare_trait_objects` Fixes https://github.com/rust-lang/rust/issues/65371
Diffstat (limited to 'src')
| -rw-r--r-- | src/librustdoc/clean/mod.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/lint/bare-trait-objects-path.rs | 18 | ||||
| -rw-r--r-- | src/test/ui/lint/bare-trait-objects-path.stderr | 29 | ||||
| -rw-r--r-- | src/test/ui/traits/impl.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/traits/inheritance/repeated-supertrait.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/traits/item-privacy.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/traits/item-privacy.stderr | 18 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/lifetimes.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/types/borrowed_box.rs | 4 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_lints/src/types/mod.rs | 2 | ||||
| -rw-r--r-- | src/tools/clippy/clippy_utils/src/hir_utils.rs | 2 |
13 files changed, 73 insertions, 26 deletions
diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index ead9d7d6646..17a961a5f66 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1477,7 +1477,7 @@ impl Clean<Type> for hir::Ty<'_> { } } TyKind::Path(_) => clean_qpath(&self, cx), - TyKind::TraitObject(ref bounds, ref lifetime) => { + TyKind::TraitObject(ref bounds, ref lifetime, _) => { match bounds[0].clean(cx).trait_ { ResolvedPath { path, param_names: None, did, is_generic } => { let mut bounds: Vec<self::GenericBound> = bounds[1..] diff --git a/src/test/ui/lint/bare-trait-objects-path.rs b/src/test/ui/lint/bare-trait-objects-path.rs new file mode 100644 index 00000000000..4c961e998df --- /dev/null +++ b/src/test/ui/lint/bare-trait-objects-path.rs @@ -0,0 +1,18 @@ +#![feature(associated_type_defaults)] + +trait Assoc { + fn func() {} + const CONST: u8 = 0; + type Ty = u8; +} + +trait Dyn {} + +impl Assoc for dyn Dyn {} + +fn main() { + Dyn::func(); //~ WARN trait objects without an explicit `dyn` are deprecated + ::Dyn::func(); //~ WARN trait objects without an explicit `dyn` are deprecated + Dyn::CONST; //~ WARN trait objects without an explicit `dyn` are deprecated + let _: Dyn::Ty; //~ ERROR ambiguous associated type +} diff --git a/src/test/ui/lint/bare-trait-objects-path.stderr b/src/test/ui/lint/bare-trait-objects-path.stderr new file mode 100644 index 00000000000..0a2dc585828 --- /dev/null +++ b/src/test/ui/lint/bare-trait-objects-path.stderr @@ -0,0 +1,29 @@ +error[E0223]: ambiguous associated type + --> $DIR/bare-trait-objects-path.rs:17:12 + | +LL | let _: Dyn::Ty; + | ^^^^^^^ help: use fully-qualified syntax: `<dyn Dyn as Trait>::Ty` + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/bare-trait-objects-path.rs:14:5 + | +LL | Dyn::func(); + | ^^^ help: use `dyn`: `<dyn Dyn>` + | + = note: `#[warn(bare_trait_objects)]` on by default + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/bare-trait-objects-path.rs:15:5 + | +LL | ::Dyn::func(); + | ^^^^^ help: use `dyn`: `<dyn (::Dyn)>` + +warning: trait objects without an explicit `dyn` are deprecated + --> $DIR/bare-trait-objects-path.rs:16:5 + | +LL | Dyn::CONST; + | ^^^ help: use `dyn`: `<dyn Dyn>` + +error: aborting due to previous error; 3 warnings emitted + +For more information about this error, try `rustc --explain E0223`. diff --git a/src/test/ui/traits/impl.rs b/src/test/ui/traits/impl.rs index 14796ce19c8..f512d91ebeb 100644 --- a/src/test/ui/traits/impl.rs +++ b/src/test/ui/traits/impl.rs @@ -30,8 +30,8 @@ fn main() { let x: &dyn T = &42; x.foo(); - T::foo(x); - T::bar(); + <dyn T>::foo(x); + <dyn T>::bar(); unsafe { assert_eq!(COUNT, 12); } diff --git a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs index 6aaef8a305b..727897d20cb 100644 --- a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs +++ b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.rs @@ -31,7 +31,7 @@ fn with_trait<C:CompareToInts>(c: &C) -> bool { } fn with_ufcs1<C:CompareToInts>(c: &C) -> bool { - CompareToInts::same_as(c, 22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfied + <dyn CompareToInts>::same_as(c, 22) //~ ERROR `dyn CompareToInts: CompareTo<i32>` is not satisfi } fn with_ufcs2<C:CompareToInts>(c: &C) -> bool { diff --git a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr index 5353b5e2260..bb11f18e545 100644 --- a/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr +++ b/src/test/ui/traits/inheritance/repeated-supertrait-ambig.stderr @@ -21,8 +21,8 @@ error[E0277]: the trait bound `dyn CompareToInts: CompareTo<i32>` is not satisfi LL | fn same_as(&self, t: T) -> bool; | -------------------------------- required by `CompareTo::same_as` ... -LL | CompareToInts::same_as(c, 22) - | ^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` +LL | <dyn CompareToInts>::same_as(c, 22) + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `CompareTo<i32>` is not implemented for `dyn CompareToInts` error[E0277]: the trait bound `C: CompareTo<i32>` is not satisfied --> $DIR/repeated-supertrait-ambig.rs:38:5 diff --git a/src/test/ui/traits/inheritance/repeated-supertrait.rs b/src/test/ui/traits/inheritance/repeated-supertrait.rs index 339f9c37eea..cb2581ffa99 100644 --- a/src/test/ui/traits/inheritance/repeated-supertrait.rs +++ b/src/test/ui/traits/inheritance/repeated-supertrait.rs @@ -31,7 +31,7 @@ fn with_trait<C:CompareToInts>(c: &C) -> bool { } fn with_ufcs1<C:CompareToInts>(c: &C) -> bool { - CompareToInts::same_as(c, 22_i64) && CompareToInts::same_as(c, 22_u64) + <dyn CompareToInts>::same_as(c, 22_i64) && <dyn CompareToInts>::same_as(c, 22_u64) } fn with_ufcs2<C:CompareToInts>(c: &C) -> bool { diff --git a/src/test/ui/traits/item-privacy.rs b/src/test/ui/traits/item-privacy.rs index 1ea1d65df62..38d06b967bc 100644 --- a/src/test/ui/traits/item-privacy.rs +++ b/src/test/ui/traits/item-privacy.rs @@ -81,8 +81,8 @@ fn check_method() { //~^ ERROR no function or associated item named `b` found S::c(&S); // OK // a, b, c are resolved as inherent items, their traits don't need to be in scope - C::a(&S); //~ ERROR associated function `a` is private - C::b(&S); // OK + <dyn C>::a(&S); //~ ERROR associated function `a` is private + <dyn C>::b(&S); // OK C::c(&S); // OK } @@ -98,9 +98,9 @@ fn check_assoc_const() { S::B; //~ ERROR no associated item named `B` found S::C; // OK // A, B, C are resolved as inherent items, their traits don't need to be in scope - C::A; //~ ERROR associated constant `A` is private - //~^ ERROR the trait `assoc_const::C` cannot be made into an object - C::B; // ERROR the trait `assoc_const::C` cannot be made into an object + <dyn C>::A; //~ ERROR associated constant `A` is private + //~^ ERROR the trait `assoc_const::C` cannot be made into an object + <dyn C>::B; // ERROR the trait `assoc_const::C` cannot be made into an object C::C; // OK } diff --git a/src/test/ui/traits/item-privacy.stderr b/src/test/ui/traits/item-privacy.stderr index b7dad54a6d3..68d527dc786 100644 --- a/src/test/ui/traits/item-privacy.stderr +++ b/src/test/ui/traits/item-privacy.stderr @@ -67,10 +67,10 @@ LL | use method::B; | error[E0624]: associated function `a` is private - --> $DIR/item-privacy.rs:84:8 + --> $DIR/item-privacy.rs:84:14 | -LL | C::a(&S); - | ^ private associated function +LL | <dyn C>::a(&S); + | ^ private associated function error[E0599]: no associated item named `A` found for struct `S` in the current scope --> $DIR/item-privacy.rs:97:8 @@ -104,16 +104,16 @@ LL | use assoc_const::B; | error[E0624]: associated constant `A` is private - --> $DIR/item-privacy.rs:101:8 + --> $DIR/item-privacy.rs:101:14 | -LL | C::A; - | ^ private associated constant +LL | <dyn C>::A; + | ^ private associated constant error[E0038]: the trait `assoc_const::C` cannot be made into an object - --> $DIR/item-privacy.rs:101:5 + --> $DIR/item-privacy.rs:101:6 | -LL | C::A; - | ^ `assoc_const::C` cannot be made into an object +LL | <dyn C>::A; + | ^^^^^ `assoc_const::C` cannot be made into an object | = help: consider moving `C` to another trait = help: consider moving `B` to another trait diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 33ff01a30e8..3ac6e6cbbef 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -387,7 +387,7 @@ impl<'a, 'tcx> Visitor<'tcx> for RefVisitor<'a, 'tcx> { self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); return; }, - TyKind::TraitObject(bounds, ref lt) => { + TyKind::TraitObject(bounds, ref lt, _) => { if !lt.is_elided() { self.unelided_trait_object_lifetime = true; } diff --git a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs index a7a511b21cf..81090040d92 100644 --- a/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs +++ b/src/tools/clippy/clippy_lints/src/types/borrowed_box.rs @@ -50,7 +50,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m // Originally reported as the issue #3128. let inner_snippet = snippet(cx, inner.span, ".."); let suggestion = match &inner.kind { - TyKind::TraitObject(bounds, lt_bound) if bounds.len() > 1 || !lt_bound.is_elided() => { + TyKind::TraitObject(bounds, lt_bound, _) if bounds.len() > 1 || !lt_bound.is_elided() => { format!("&{}({})", ltopt, &inner_snippet) }, TyKind::Path(qpath) @@ -86,7 +86,7 @@ pub(super) fn check(cx: &LateContext<'_>, hir_ty: &hir::Ty<'_>, lt: &Lifetime, m // Returns true if given type is `Any` trait. fn is_any_trait(t: &hir::Ty<'_>) -> bool { if_chain! { - if let TyKind::TraitObject(ref traits, _) = t.kind; + if let TyKind::TraitObject(ref traits, ..) = t.kind; if !traits.is_empty(); // Only Send/Sync can be used as additional traits, so it is enough to // check only the first trait. diff --git a/src/tools/clippy/clippy_lints/src/types/mod.rs b/src/tools/clippy/clippy_lints/src/types/mod.rs index f7a6399a7f0..4a1a608e8ae 100644 --- a/src/tools/clippy/clippy_lints/src/types/mod.rs +++ b/src/tools/clippy/clippy_lints/src/types/mod.rs @@ -911,7 +911,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { // function types bring a lot of overhead TyKind::BareFn(ref bare) if bare.abi == Abi::Rust => (50 * self.nest, 1), - TyKind::TraitObject(ref param_bounds, _) => { + TyKind::TraitObject(ref param_bounds, ..) => { let has_lifetime_parameters = param_bounds.iter().any(|bound| { bound .bound_generic_params diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index af82f992d56..7f7d9c5f56a 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -892,7 +892,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { TyKind::OpaqueDef(_, arg_list) => { self.hash_generic_args(arg_list); }, - TyKind::TraitObject(_, lifetime) => { + TyKind::TraitObject(_, lifetime, _) => { self.hash_lifetime(lifetime); }, TyKind::Typeof(anon_const) => { |
