diff options
Diffstat (limited to 'compiler/rustc_lint_defs/src/builtin.rs')
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 46 |
1 files changed, 44 insertions, 2 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 33cb35e60eb..28317d6cea0 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -1405,7 +1405,7 @@ declare_lint! { /// struct S; /// /// impl S { - /// fn late<'a, 'b>(self, _: &'a u8, _: &'b u8) {} + /// fn late(self, _: &u8, _: &u8) {} /// } /// /// fn main() { @@ -3311,6 +3311,7 @@ declare_lint_pass! { FFI_UNWIND_CALLS, REPR_TRANSPARENT_EXTERNAL_PRIVATE_FIELDS, NAMED_ARGUMENTS_USED_POSITIONALLY, + IMPLIED_BOUNDS_ENTAILMENT, ] } @@ -3580,7 +3581,7 @@ declare_lint! { /// fn main() { /// let x: String = "3".try_into().unwrap(); /// // ^^^^^^^^ - /// // This call to try_into matches both Foo:try_into and TryInto::try_into as + /// // This call to try_into matches both Foo::try_into and TryInto::try_into as /// // `TryInto` has been added to the Rust prelude in 2021 edition. /// println!("{x}"); /// } @@ -3998,3 +3999,44 @@ declare_lint! { Warn, "named arguments in format used positionally" } + +declare_lint! { + /// The `implied_bounds_entailment` lint detects cases where the arguments of an impl method + /// have stronger implied bounds than those from the trait method it's implementing. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![deny(implied_bounds_entailment)] + /// + /// trait Trait { + /// fn get<'s>(s: &'s str, _: &'static &'static ()) -> &'static str; + /// } + /// + /// impl Trait for () { + /// fn get<'s>(s: &'s str, _: &'static &'s ()) -> &'static str { + /// s + /// } + /// } + /// + /// let val = <() as Trait>::get(&String::from("blah blah blah"), &&()); + /// println!("{}", val); + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// Neither the trait method, which provides no implied bounds about `'s`, nor the impl, + /// 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, + Warn, + "impl method assumes more implied bounds than its corresponding trait method", + @future_incompatible = FutureIncompatibleInfo { + reference: "issue #105572 <https://github.com/rust-lang/rust/issues/105572>", + reason: FutureIncompatibilityReason::FutureReleaseError, + }; +} |
