Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/accepted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ declare_features! (
(accepted, struct_field_attributes, "1.20.0", Some(38814)),
/// Allows struct variants `Foo { baz: u8, .. }` in enums (RFC 418).
(accepted, struct_variant, "1.0.0", None),
/// Allows subtrait items to shadow supertrait items.
(accepted, supertrait_item_shadowing, "CURRENT_RUSTC_VERSION", Some(89151)),
/// Allows `#[target_feature(...)]`.
(accepted, target_feature, "1.27.0", None),
/// Allows the use of `#[target_feature]` on safe functions.
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_feature/src/unstable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,8 +648,6 @@ declare_features! (
(unstable, string_deref_patterns, "1.67.0", Some(87121)),
/// Allows `super let` statements.
(unstable, super_let, "1.88.0", Some(139076)),
/// Allows subtrait items to shadow supertrait items.
(unstable, supertrait_item_shadowing, "1.86.0", Some(89151)),
/// Allows the use of target_feature when a function is marked inline(always).
(unstable, target_feature_inline_always, "1.91.0", Some(145574)),
/// Allows using `#[thread_local]` on `static` items.
Expand Down
10 changes: 4 additions & 6 deletions compiler/rustc_hir_typeck/src/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1728,12 +1728,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
// We collapse to a subtrait pick *after* filtering unstable candidates
// to make sure we don't prefer a unstable subtrait method over a stable
// supertrait method.
if self.tcx.features().supertrait_item_shadowing() {
if let Some(pick) =
self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
{
return Some(Ok(pick));
}
if let Some(pick) =
self.collapse_candidates_to_subtrait_pick(self_ty, &applicable_candidates)
{
return Some(Ok(pick));
}

let sources =
Expand Down
8 changes: 1 addition & 7 deletions compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4923,11 +4923,8 @@ declare_lint! {
/// 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! {
Expand Down Expand Up @@ -4962,11 +4959,8 @@ declare_lint! {
/// 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,
Warn,
"detects when a supertrait item is shadowed by a subtrait item",
@feature_gate = supertrait_item_shadowing;
}

declare_lint! {
Expand Down
10 changes: 5 additions & 5 deletions compiler/rustc_middle/src/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub trait Provenance: Copy + PartialEq + fmt::Debug + 'static {
const WILDCARD: Option<Self>;

/// Determines how a pointer should be printed.
fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;
fn fmt_ptr(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result;

/// If `OFFSET_IS_ADDR == false`, provenance must always be able to
/// identify the allocation this ptr points to (i.e., this must return `Some`).
Expand Down Expand Up @@ -174,7 +174,7 @@ impl Provenance for CtfeProvenance {
// `CtfeProvenance` does not implement wildcard provenance.
const WILDCARD: Option<Self> = None;

fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_ptr(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Print AllocId.
fmt::Debug::fmt(&ptr.provenance.alloc_id(), f)?; // propagates `alternate` flag
// Print offset only if it is non-zero.
Expand Down Expand Up @@ -206,7 +206,7 @@ impl Provenance for AllocId {
// `AllocId` does not implement wildcard provenance.
const WILDCARD: Option<Self> = None;

fn fmt(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_ptr(ptr: &Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Forward `alternate` flag to `alloc_id` printing.
if f.alternate() {
write!(f, "{:#?}", ptr.provenance)?;
Expand Down Expand Up @@ -248,14 +248,14 @@ static_assert_size!(Pointer<Option<CtfeProvenance>>, 16);
// all the Miri types.
impl<Prov: Provenance> fmt::Debug for Pointer<Prov> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Provenance::fmt(self, f)
Provenance::fmt_ptr(self, f)
}
}

impl<Prov: Provenance> fmt::Debug for Pointer<Option<Prov>> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self.provenance {
Some(prov) => Provenance::fmt(&Pointer::new(prov, self.offset), f),
Some(prov) => Provenance::fmt_ptr(&Pointer::new(prov, self.offset), f),
None => write!(f, "{:#x}[noalloc]", self.offset.bytes()),
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ trait UAddSub: DInt + Int {

impl UAddSub for u128 {}

#[allow(supertrait_item_shadowing_definition)]
trait AddSub: Int
where
<Self as MinInt>::Unsigned: UAddSub,
Expand Down
1 change: 1 addition & 0 deletions library/compiler-builtins/compiler-builtins/src/int/mul.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::int::{DInt, HInt, Int};

#[allow(supertrait_item_shadowing_definition)]
trait Mul: DInt + Int
where
Self::H: DInt,
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/array/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ impl<T: Copy, const N: usize> Copy for [T; N] {}
impl<T: Clone, const N: usize> Clone for [T; N] {
#[inline]
fn clone(&self) -> Self {
SpecArrayClone::clone(self)
SpecArrayClone::spec_clone(self)
}

#[inline]
Expand All @@ -452,19 +452,19 @@ impl<T: Clone, const N: usize> Clone for [T; N] {
}

trait SpecArrayClone: Clone {
fn clone<const N: usize>(array: &[Self; N]) -> [Self; N];
fn spec_clone<const N: usize>(array: &[Self; N]) -> [Self; N];
}

impl<T: Clone> SpecArrayClone for T {
#[inline]
default fn clone<const N: usize>(array: &[T; N]) -> [T; N] {
default fn spec_clone<const N: usize>(array: &[T; N]) -> [T; N] {
from_trusted_iterator(array.iter().cloned())
}
}

impl<T: Copy> SpecArrayClone for T {
#[inline]
fn clone<const N: usize>(array: &[T; N]) -> [T; N] {
fn spec_clone<const N: usize>(array: &[T; N]) -> [T; N] {
*array
}
}
Expand Down
8 changes: 4 additions & 4 deletions library/core/src/iter/adapters/array_chunks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
{
<Self as SpecFold>::fold(self, init, f)
<Self as SpecFold>::spec_fold(self, init, f)
}
}

Expand Down Expand Up @@ -196,7 +196,7 @@ where
}

trait SpecFold: Iterator {
fn fold<B, F>(self, init: B, f: F) -> B
fn spec_fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B;
Expand All @@ -207,7 +207,7 @@ where
I: Iterator,
{
#[inline]
default fn fold<B, F>(mut self, init: B, f: F) -> B
default fn spec_fold<B, F>(mut self, init: B, f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
Expand All @@ -221,7 +221,7 @@ where
I: Iterator + TrustedRandomAccessNoCoerce,
{
#[inline]
fn fold<B, F>(mut self, init: B, mut f: F) -> B
fn spec_fold<B, F>(mut self, init: B, mut f: F) -> B
where
Self: Sized,
F: FnMut(B, Self::Item) -> B,
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/implied_bounds_in_impls.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn issue11880() {
type U;
}
trait Y: X {
#[allow(supertrait_item_shadowing_definition)]
type T;
type V;
}
Expand Down
1 change: 1 addition & 0 deletions src/tools/clippy/tests/ui/implied_bounds_in_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ fn issue11880() {
type U;
}
trait Y: X {
#[allow(supertrait_item_shadowing_definition)]
type T;
type V;
}
Expand Down
14 changes: 7 additions & 7 deletions src/tools/clippy/tests/ui/implied_bounds_in_impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ LL + fn f3() -> impl Trait4<i8, X = i32, Y = i128> {}
|

error: this bound is already specified as the supertrait of `Y`
--> tests/ui/implied_bounds_in_impls.rs:165:21
--> tests/ui/implied_bounds_in_impls.rs:166:21
|
LL | fn f3() -> impl X + Y {}
| ^
Expand All @@ -205,7 +205,7 @@ LL + fn f3() -> impl Y {}
|

error: this bound is already specified as the supertrait of `Y<T = u32>`
--> tests/ui/implied_bounds_in_impls.rs:167:21
--> tests/ui/implied_bounds_in_impls.rs:168:21
|
LL | fn f4() -> impl X + Y<T = u32> {}
| ^
Expand All @@ -217,7 +217,7 @@ LL + fn f4() -> impl Y<T = u32> {}
|

error: this bound is already specified as the supertrait of `Y<T = u32>`
--> tests/ui/implied_bounds_in_impls.rs:169:21
--> tests/ui/implied_bounds_in_impls.rs:170:21
|
LL | fn f5() -> impl X<U = String> + Y<T = u32> {}
| ^^^^^^^^^^^^^
Expand All @@ -229,7 +229,7 @@ LL + fn f5() -> impl Y<T = u32, U = String> {}
|

error: this bound is already specified as the supertrait of `DerefMut`
--> tests/ui/implied_bounds_in_impls.rs:173:17
--> tests/ui/implied_bounds_in_impls.rs:174:17
|
LL | fn apit(_: impl Deref + DerefMut) {}
| ^^^^^
Expand All @@ -241,7 +241,7 @@ LL + fn apit(_: impl DerefMut) {}
|

error: this bound is already specified as the supertrait of `DerefMut`
--> tests/ui/implied_bounds_in_impls.rs:177:20
--> tests/ui/implied_bounds_in_impls.rs:178:20
|
LL | fn f() -> impl Deref + DerefMut;
| ^^^^^
Expand All @@ -253,7 +253,7 @@ LL + fn f() -> impl DerefMut;
|

error: this bound is already specified as the supertrait of `DerefMut`
--> tests/ui/implied_bounds_in_impls.rs:186:23
--> tests/ui/implied_bounds_in_impls.rs:187:23
|
LL | type Assoc = impl Deref + DerefMut;
| ^^^^^
Expand All @@ -265,7 +265,7 @@ LL + type Assoc = impl DerefMut;
|

error: this bound is already specified as the supertrait of `DerefMut`
--> tests/ui/implied_bounds_in_impls.rs:193:18
--> tests/ui/implied_bounds_in_impls.rs:194:18
|
LL | type Tait = impl Deref + DerefMut;
| ^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl interpret::Provenance for Provenance {
}
}

fn fmt(ptr: &interpret::Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fn fmt_ptr(ptr: &interpret::Pointer<Self>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let (prov, addr) = ptr.into_raw_parts(); // offset is absolute address
write!(f, "{:#x}", addr.bytes())?;
if f.alternate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
//@ check-pass

#![feature(associated_const_equality)]
#![allow(supertrait_item_shadowing_definition)]

trait Trait: SuperTrait {
type N;
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/associated-consts/shadowed-const.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Checking that none of these ICE, which was introduced in
// https://github.com/rust-lang/rust/issues/93553

#![allow(supertrait_item_shadowing_definition)]

trait Foo {
type Bar;
}
Expand All @@ -15,9 +18,9 @@ trait Baz2: Foo {
}

trait Baz3 {
const BAR: usize;
const QUX: Self::BAR;
//~^ ERROR expected type, found constant
const BAR: usize;
const QUX: Self::BAR;
//~^ ERROR expected type, found constant
}

fn main() {}
12 changes: 6 additions & 6 deletions tests/ui/associated-consts/shadowed-const.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error: expected type, found constant
--> $DIR/shadowed-const.rs:19:20
--> $DIR/shadowed-const.rs:22:22
|
LL | const QUX: Self::BAR;
| ^^^ unexpected constant
LL | const QUX: Self::BAR;
| ^^^ unexpected constant
|
note: the associated constant is defined here
--> $DIR/shadowed-const.rs:18:3
--> $DIR/shadowed-const.rs:21:5
|
LL | const BAR: usize;
| ^^^^^^^^^^^^^^^^
LL | const BAR: usize;
| ^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Test that no help message is emitted that suggests renaming the
// associated type from a non-local trait

#![allow(supertrait_item_shadowing_definition)]

pub trait NewIter: Iterator {
type Item;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0191]: the value of the associated type `Item` in `Iterator` must be specified
--> $DIR/associated-type-shadowed-from-non-local-supertrait.rs:8:27
--> $DIR/associated-type-shadowed-from-non-local-supertrait.rs:10:27
|
LL | type Item;
| --------- `Iterator::Item` shadowed here, consider renaming it
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Test Setting the value of an associated type
// that is shadowed from a supertrait

#![allow(supertrait_item_shadowing_definition)]

pub trait Super {
type X;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0191]: the value of the associated type `X` in `Super` must be specified
--> $DIR/associated-type-shadowed-from-supertrait.rs:12:27
--> $DIR/associated-type-shadowed-from-supertrait.rs:14:27
|
LL | type X;
| ------ `Super::X` defined here, consider renaming it
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/associated-types/issue-20825-2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![allow(supertrait_item_shadowing_definition)]

//@ check-pass
pub trait Subscriber {
type Input;
Expand Down
1 change: 1 addition & 0 deletions tests/ui/delegation/explicit-paths-in-traits-pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#![feature(fn_delegation)]
#![allow(incomplete_features)]
#![allow(supertrait_item_shadowing_definition)]

trait ToReuse {
fn foo(&self, x: i32) -> i32 { x }
Expand Down
1 change: 1 addition & 0 deletions tests/ui/delegation/explicit-paths.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#![feature(fn_delegation)]
#![allow(incomplete_features)]
#![allow(supertrait_item_shadowing_definition)]

trait Trait {
fn foo1(&self, x: i32) -> i32 { x }
Expand Down
Loading
Loading