diff options
Diffstat (limited to 'compiler/rustc_lint_defs/src/builtin.rs')
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 91 |
1 files changed, 87 insertions, 4 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 9561b3de5f8..97850a2afc1 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -101,6 +101,8 @@ declare_lint_pass! { SINGLE_USE_LIFETIMES, SOFT_UNSTABLE, STABLE_FEATURES, + SUPERTRAIT_ITEM_SHADOWING_DEFINITION, + SUPERTRAIT_ITEM_SHADOWING_USAGE, TAIL_EXPR_DROP_ORDER, TEST_UNSTABLE_LINT, TEXT_DIRECTION_CODEPOINT_IN_COMMENT, @@ -2778,7 +2780,7 @@ declare_lint! { /// /// ```rust /// enum Void {} - /// extern { + /// unsafe extern { /// static EXTERN: Void; /// } /// ``` @@ -4009,7 +4011,7 @@ declare_lint! { /// ```rust /// #![warn(ffi_unwind_calls)] /// - /// extern "C-unwind" { + /// unsafe extern "C-unwind" { /// fn foo(); /// } /// @@ -4753,7 +4755,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,edition2021 /// #![warn(missing_unsafe_on_extern)] /// #![allow(dead_code)] /// @@ -4790,7 +4792,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,edition2021 /// #![warn(unsafe_attr_outside_unsafe)] /// /// #[no_mangle] @@ -4917,6 +4919,87 @@ declare_lint! { } declare_lint! { + /// The `supertrait_item_shadowing_usage` lint detects when the + /// usage of an item that is provided by both a subtrait and supertrait + /// is shadowed, preferring the subtrait. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![feature(supertrait_item_shadowing)] + /// #![deny(supertrait_item_shadowing_usage)] + /// + /// trait Upstream { + /// fn hello(&self) {} + /// } + /// impl<T> Upstream for T {} + /// + /// trait Downstream: Upstream { + /// fn hello(&self) {} + /// } + /// impl<T> Downstream for T {} + /// + /// struct MyType; + /// MyType.hello(); + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// RFC 3624 specified a heuristic in which a supertrait item would be + /// shadowed by a subtrait item when ambiguity occurs during item + /// selection. In order to mitigate side-effects of this happening + /// silently, this lint detects these cases when users want to deny them + /// or fix the call sites. + pub SUPERTRAIT_ITEM_SHADOWING_USAGE, + // FIXME(supertrait_item_shadowing): It is not decided if this should + // warn by default at the call site. + Allow, + "detects when a supertrait item is shadowed by a subtrait item", + @feature_gate = supertrait_item_shadowing; +} + +declare_lint! { + /// The `supertrait_item_shadowing_definition` lint detects when the + /// definition of an item that is provided by both a subtrait and + /// supertrait is shadowed, preferring the subtrait. + /// + /// ### Example + /// + /// ```rust,compile_fail + /// #![feature(supertrait_item_shadowing)] + /// #![deny(supertrait_item_shadowing_definition)] + /// + /// trait Upstream { + /// fn hello(&self) {} + /// } + /// impl<T> Upstream for T {} + /// + /// trait Downstream: Upstream { + /// fn hello(&self) {} + /// } + /// impl<T> Downstream for T {} + /// ``` + /// + /// {{produces}} + /// + /// ### Explanation + /// + /// RFC 3624 specified a heuristic in which a supertrait item would be + /// shadowed by a subtrait item when ambiguity occurs during item + /// selection. In order to mitigate side-effects of this happening + /// silently, this lint detects these cases when users want to deny them + /// or fix their trait definitions. + pub SUPERTRAIT_ITEM_SHADOWING_DEFINITION, + // FIXME(supertrait_item_shadowing): It is not decided if this should + // warn by default at the usage site. + Allow, + "detects when a supertrait item is shadowed by a subtrait item", + @feature_gate = supertrait_item_shadowing; +} + +declare_lint! { /// The `ptr_to_integer_transmute_in_consts` lint detects pointer to integer /// transmute in const functions and associated constants. /// |
