From 96154d7fa7ced3184b69645ed8b6e7c210ca15b4 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 11 Dec 2022 21:16:43 +0000 Subject: Add IMPLIED_BOUNDS_ENTAILMENT lint --- ...pl-implied-bounds-compatibility-unnormalized.rs | 20 +++++++++++++++++++ ...mplied-bounds-compatibility-unnormalized.stderr | 23 ++++++++++++++++++++++ .../impl-implied-bounds-compatibility.rs | 19 ++++++++++++++++++ .../impl-implied-bounds-compatibility.stderr | 23 ++++++++++++++++++++++ 4 files changed, 85 insertions(+) create mode 100644 src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs create mode 100644 src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr create mode 100644 src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs create mode 100644 src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr (limited to 'src/test') diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs new file mode 100644 index 00000000000..cb5d83abfb6 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs @@ -0,0 +1,20 @@ +trait Project { + type Ty; +} +impl Project for &'_ &'_ () { + type Ty = (); +} +trait Trait { + fn get<'s>(s: &'s str, _: ()) -> &'static str; +} +impl Trait for () { + fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { + //~^ ERROR impl method assumes more implied bounds than the corresponding trait method + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + s + } +} +fn main() { + let val = <() as Trait>::get(&String::from("blah blah blah"), ()); + println!("{}", val); +} diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr new file mode 100644 index 00000000000..5a757901777 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr @@ -0,0 +1,23 @@ +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:5 + | +LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 + = note: `#[deny(implied_bounds_entailment)]` on by default + +error: aborting due to previous error + +Future incompatibility report: Future breakage diagnostic: +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:5 + | +LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 + = note: `#[deny(implied_bounds_entailment)]` on by default + diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs new file mode 100644 index 00000000000..2d7cc38d263 --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs @@ -0,0 +1,19 @@ +use std::cell::RefCell; + +pub struct MessageListeners<'a> { + listeners: RefCell>>, +} + +pub trait MessageListenersInterface { + fn listeners<'c>(&'c self) -> &'c MessageListeners<'c>; +} + +impl<'a> MessageListenersInterface for MessageListeners<'a> { + fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { + //~^ ERROR impl method assumes more implied bounds than the corresponding trait method + //~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + self + } +} + +fn main() {} diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr new file mode 100644 index 00000000000..b7dbfc8ab8c --- /dev/null +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr @@ -0,0 +1,23 @@ +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility.rs:12:5 + | +LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 + = note: `#[deny(implied_bounds_entailment)]` on by default + +error: aborting due to previous error + +Future incompatibility report: Future breakage diagnostic: +error: impl method assumes more implied bounds than the corresponding trait method + --> $DIR/impl-implied-bounds-compatibility.rs:12:5 + | +LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | + = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! + = note: for more information, see issue #105572 + = note: `#[deny(implied_bounds_entailment)]` on by default + -- cgit 1.4.1-3-g733a5 From c40ededa10439e64f20ee45f3cdd50d893f20438 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Fri, 16 Dec 2022 19:30:32 +0000 Subject: Downgrade IMPLIED_BOUNDS_ENTAILMENT to warn by default, add it to builtin lint list --- compiler/rustc_lint_defs/src/builtin.rs | 9 +++++---- .../impl-implied-bounds-compatibility-unnormalized.rs | 2 ++ ...l-implied-bounds-compatibility-unnormalized.stderr | 19 ++++++------------- .../impl-implied-bounds-compatibility.rs | 2 ++ .../impl-implied-bounds-compatibility.stderr | 19 ++++++------------- 5 files changed, 21 insertions(+), 30 deletions(-) (limited to 'src/test') diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index c88158da763..f7a4103f4d5 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -3311,6 +3311,7 @@ declare_lint_pass! { FFI_UNWIND_CALLS, REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, NAMED_ARGUMENTS_USED_POSITIONALLY, + IMPLIED_BOUNDS_ENTAILMENT, ] } @@ -4027,15 +4028,15 @@ declare_lint! { /// ### Explanation /// /// Neither the trait method, which provides no implied bounds about `'s`, nor the impl, - /// which can't name `'s`, requires the main function to prove that 's: 'static, but the - /// impl method is able to assume that 's: 'static within its own body. + /// requires the main function to prove that 's: 'static, but the impl method is allowed + /// to assume that `'s: 'static` within its own body. /// /// This can be used to implement an unsound API if used incorrectly. pub IMPLIED_BOUNDS_ENTAILMENT, - Deny, + Warn, "impl method assumes more implied bounds than its corresponding trait method", @future_incompatible = FutureIncompatibleInfo { reference: "issue #105572 ", - reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow, + reason: FutureIncompatibilityReason::FutureReleaseError, }; } diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs index cb5d83abfb6..6ccbb5bb266 100644 --- a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.rs @@ -1,3 +1,5 @@ +#![deny(implied_bounds_entailment)] + trait Project { type Ty; } diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr index 5a757901777..0ac31c642eb 100644 --- a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility-unnormalized.stderr @@ -1,23 +1,16 @@ error: impl method assumes more implied bounds than the corresponding trait method - --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:5 + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:13:5 | LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #105572 - = note: `#[deny(implied_bounds_entailment)]` on by default +note: the lint level is defined here + --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:1:9 + | +LL | #![deny(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error -Future incompatibility report: Future breakage diagnostic: -error: impl method assumes more implied bounds than the corresponding trait method - --> $DIR/impl-implied-bounds-compatibility-unnormalized.rs:11:5 - | -LL | fn get<'s>(s: &'s str, _: <&'static &'s () as Project>::Ty) -> &'static str { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #105572 - = note: `#[deny(implied_bounds_entailment)]` on by default - diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs index 2d7cc38d263..d097bc16a22 100644 --- a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.rs @@ -1,3 +1,5 @@ +#![deny(implied_bounds_entailment)] + use std::cell::RefCell; pub struct MessageListeners<'a> { diff --git a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr index b7dbfc8ab8c..0dfa8167a99 100644 --- a/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr +++ b/src/test/ui/implied-bounds/impl-implied-bounds-compatibility.stderr @@ -1,23 +1,16 @@ error: impl method assumes more implied bounds than the corresponding trait method - --> $DIR/impl-implied-bounds-compatibility.rs:12:5 + --> $DIR/impl-implied-bounds-compatibility.rs:14:5 | LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! = note: for more information, see issue #105572 - = note: `#[deny(implied_bounds_entailment)]` on by default +note: the lint level is defined here + --> $DIR/impl-implied-bounds-compatibility.rs:1:9 + | +LL | #![deny(implied_bounds_entailment)] + | ^^^^^^^^^^^^^^^^^^^^^^^^^ error: aborting due to previous error -Future incompatibility report: Future breakage diagnostic: -error: impl method assumes more implied bounds than the corresponding trait method - --> $DIR/impl-implied-bounds-compatibility.rs:12:5 - | -LL | fn listeners<'b>(&'b self) -> &'a MessageListeners<'b> { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! - = note: for more information, see issue #105572 - = note: `#[deny(implied_bounds_entailment)]` on by default - -- cgit 1.4.1-3-g733a5