diff options
| author | Michael Goulet <michael@errs.io> | 2025-01-25 17:14:33 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-13 05:45:53 +0000 |
| commit | 72b4df3772a6c2cae8d9cf7ae618c010c10131b2 (patch) | |
| tree | 7c2d611b8fce4d6776b7579df0a65d8078399290 /compiler/rustc_lint_defs/src | |
| parent | 2189908170f86809b7de5275dcde0cf828c16b37 (diff) | |
| download | rust-72b4df3772a6c2cae8d9cf7ae618c010c10131b2.tar.gz rust-72b4df3772a6c2cae8d9cf7ae618c010c10131b2.zip | |
Implement lint for definition site item shadowing too
Diffstat (limited to 'compiler/rustc_lint_defs/src')
| -rw-r--r-- | compiler/rustc_lint_defs/src/builtin.rs | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/compiler/rustc_lint_defs/src/builtin.rs b/compiler/rustc_lint_defs/src/builtin.rs index 55fa7d9d86c..10bf4ec77ed 100644 --- a/compiler/rustc_lint_defs/src/builtin.rs +++ b/compiler/rustc_lint_defs/src/builtin.rs @@ -101,6 +101,7 @@ 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, @@ -4924,7 +4925,7 @@ declare_lint! { /// /// ### Example /// - /// ```rust + /// ```rust,compile_fail /// #![feature(supertrait_item_shadowing)] /// #![deny(supertrait_item_shadowing_usage)] /// @@ -4960,6 +4961,45 @@ declare_lint! { } 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. /// |
