Skip to content

Commit 97b0ece

Browse files
Rollup merge of rust-lang#103048 - Dylan-DPC:rollup-47r62js, r=Dylan-DPC
Rollup of 8 pull requests Successful merges: - rust-lang#102847 (impl AsFd and AsRawFd for io::{Stdin, Stdout, Stderr}, not the sys versions) - rust-lang#102856 (Only test duplicate inherent impl items in a single place) - rust-lang#102914 (Migrate css highlight without change) - rust-lang#102938 (Move some tests to more reasonable directories) - rust-lang#103015 (fix a typo) - rust-lang#103018 (More dupe word typos) - rust-lang#103025 (rustdoc: remove unused CSS `.search-container > *`) - rust-lang#103031 (Suppress irrefutable let patterns lint for prefixes in match guards) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents c6f23ed + 7cf09c5 commit 97b0ece

29 files changed

+68
-104
lines changed

compiler/rustc_hir_analysis/src/coherence/inherent_impls_overlap.rs

+35-6
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,37 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
5858
== item2.ident(self.tcx).normalize_to_macros_2_0()
5959
}
6060

61+
fn check_for_duplicate_items_in_impl(&self, impl_: DefId) {
62+
let impl_items = self.tcx.associated_items(impl_);
63+
64+
let mut seen_items = FxHashMap::default();
65+
for impl_item in impl_items.in_definition_order() {
66+
let span = self.tcx.def_span(impl_item.def_id);
67+
let ident = impl_item.ident(self.tcx);
68+
69+
let norm_ident = ident.normalize_to_macros_2_0();
70+
match seen_items.entry(norm_ident) {
71+
Entry::Occupied(entry) => {
72+
let former = entry.get();
73+
let mut err = struct_span_err!(
74+
self.tcx.sess,
75+
span,
76+
E0592,
77+
"duplicate definitions with name `{}`",
78+
ident,
79+
);
80+
err.span_label(span, format!("duplicate definitions for `{}`", ident));
81+
err.span_label(*former, format!("other definition for `{}`", ident));
82+
83+
err.emit();
84+
}
85+
Entry::Vacant(entry) => {
86+
entry.insert(span);
87+
}
88+
}
89+
}
90+
}
91+
6192
fn check_for_common_items_in_impls(
6293
&self,
6394
impl1: DefId,
@@ -133,12 +164,6 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
133164

134165
let impls = self.tcx.inherent_impls(id.def_id);
135166

136-
// If there is only one inherent impl block,
137-
// there is nothing to overlap check it with
138-
if impls.len() <= 1 {
139-
return;
140-
}
141-
142167
let overlap_mode = OverlapMode::get(self.tcx, id.def_id.to_def_id());
143168

144169
let impls_items = impls
@@ -152,6 +177,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
152177
const ALLOCATING_ALGO_THRESHOLD: usize = 500;
153178
if impls.len() < ALLOCATING_ALGO_THRESHOLD {
154179
for (i, &(&impl1_def_id, impl_items1)) in impls_items.iter().enumerate() {
180+
self.check_for_duplicate_items_in_impl(impl1_def_id);
181+
155182
for &(&impl2_def_id, impl_items2) in &impls_items[(i + 1)..] {
156183
if self.impls_have_common_items(impl_items1, impl_items2) {
157184
self.check_for_overlapping_inherent_impls(
@@ -290,6 +317,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
290317
impl_blocks.sort_unstable();
291318
for (i, &impl1_items_idx) in impl_blocks.iter().enumerate() {
292319
let &(&impl1_def_id, impl_items1) = &impls_items[impl1_items_idx];
320+
self.check_for_duplicate_items_in_impl(impl1_def_id);
321+
293322
for &impl2_items_idx in impl_blocks[(i + 1)..].iter() {
294323
let &(&impl2_def_id, impl_items2) = &impls_items[impl2_items_idx];
295324
if self.impls_have_common_items(impl_items1, impl_items2) {

compiler/rustc_hir_analysis/src/impl_wf_check.rs

+1-39
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,14 @@
1111
use crate::constrained_generic_params as cgp;
1212
use min_specialization::check_min_specialization;
1313

14-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
14+
use rustc_data_structures::fx::FxHashSet;
1515
use rustc_errors::struct_span_err;
1616
use rustc_hir::def::DefKind;
1717
use rustc_hir::def_id::LocalDefId;
1818
use rustc_middle::ty::query::Providers;
1919
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
2020
use rustc_span::{Span, Symbol};
2121

22-
use std::collections::hash_map::Entry::{Occupied, Vacant};
23-
2422
mod min_specialization;
2523

2624
/// Checks that all the type/lifetime parameters on an impl also
@@ -59,7 +57,6 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
5957
for id in module.items() {
6058
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
6159
enforce_impl_params_are_constrained(tcx, id.def_id.def_id);
62-
enforce_impl_items_are_distinct(tcx, id.def_id.def_id);
6360
if min_specialization {
6461
check_min_specialization(tcx, id.def_id.def_id);
6562
}
@@ -194,38 +191,3 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol
194191
}
195192
err.emit();
196193
}
197-
198-
/// Enforce that we do not have two items in an impl with the same name.
199-
fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) {
200-
if tcx.impl_trait_ref(impl_def_id).is_some() {
201-
return;
202-
}
203-
let mut seen_type_items = FxHashMap::default();
204-
let mut seen_value_items = FxHashMap::default();
205-
for &impl_item_ref in tcx.associated_item_def_ids(impl_def_id) {
206-
let impl_item = tcx.associated_item(impl_item_ref);
207-
let seen_items = match impl_item.kind {
208-
ty::AssocKind::Type => &mut seen_type_items,
209-
_ => &mut seen_value_items,
210-
};
211-
let span = tcx.def_span(impl_item_ref);
212-
let ident = impl_item.ident(tcx);
213-
match seen_items.entry(ident.normalize_to_macros_2_0()) {
214-
Occupied(entry) => {
215-
let mut err = struct_span_err!(
216-
tcx.sess,
217-
span,
218-
E0201,
219-
"duplicate definitions with name `{}`:",
220-
ident
221-
);
222-
err.span_label(*entry.get(), format!("previous definition of `{}` here", ident));
223-
err.span_label(span, "duplicate definition");
224-
err.emit();
225-
}
226-
Vacant(entry) => {
227-
entry.insert(span);
228-
}
229-
}
230-
}
231-
}
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0201]: duplicate definitions with name `bar`:
1+
error[E0592]: duplicate definitions with name `bar`
22
--> $DIR/associated-item-duplicate-names-2.rs:5:5
33
|
44
LL | const bar: bool = true;
5-
| --------------- previous definition of `bar` here
5+
| --------------- other definition for `bar`
66
LL | fn bar() {}
7-
| ^^^^^^^^ duplicate definition
7+
| ^^^^^^^^ duplicate definitions for `bar`
88

99
error: aborting due to previous error
1010

11-
For more information about this error, try `rustc --explain E0201`.
11+
For more information about this error, try `rustc --explain E0592`.

src/test/ui/impl-duplicate-methods.rs renamed to src/test/ui/associated-item/impl-duplicate-methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ struct Foo;
33
impl Foo {
44
fn orange(&self) {}
55
fn orange(&self) {}
6-
//~^ ERROR duplicate definition
6+
//~^ ERROR duplicate definitions with name `orange` [E0592]
77
}
88

99
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0592]: duplicate definitions with name `orange`
2+
--> $DIR/impl-duplicate-methods.rs:5:5
3+
|
4+
LL | fn orange(&self) {}
5+
| ---------------- other definition for `orange`
6+
LL | fn orange(&self) {}
7+
| ^^^^^^^^^^^^^^^^ duplicate definitions for `orange`
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0592`.
File renamed without changes.

src/test/ui/error-codes/E0201.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ struct Foo(u8);
22

33
impl Foo {
44
fn bar(&self) -> bool { self.0 > 5 }
5-
fn bar() {} //~ ERROR E0201
5+
fn bar() {} //~ ERROR E0592
66
}
77

88
trait Baz {

src/test/ui/error-codes/E0201.stderr

+5-4
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@ LL | type Quux = u32;
2121
LL | type Quux = u32;
2222
| ^^^^^^^^^^^^^^^^ duplicate definition
2323

24-
error[E0201]: duplicate definitions with name `bar`:
24+
error[E0592]: duplicate definitions with name `bar`
2525
--> $DIR/E0201.rs:5:5
2626
|
2727
LL | fn bar(&self) -> bool { self.0 > 5 }
28-
| --------------------- previous definition of `bar` here
28+
| --------------------- other definition for `bar`
2929
LL | fn bar() {}
30-
| ^^^^^^^^ duplicate definition
30+
| ^^^^^^^^ duplicate definitions for `bar`
3131

3232
error: aborting due to 3 previous errors
3333

34-
For more information about this error, try `rustc --explain E0201`.
34+
Some errors have detailed explanations: E0201, E0592.
35+
For more information about an error, try `rustc --explain E0201`.

src/test/ui/impl-duplicate-methods.stderr

-11
This file was deleted.

src/test/ui/issues/issue-4265.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error[E0201]: duplicate definitions with name `bar`:
1+
error[E0592]: duplicate definitions with name `bar`
22
--> $DIR/issue-4265.rs:10:5
33
|
44
LL | fn bar() {
5-
| -------- previous definition of `bar` here
5+
| -------- other definition for `bar`
66
...
77
LL | fn bar() {
8-
| ^^^^^^^^ duplicate definition
8+
| ^^^^^^^^ duplicate definitions for `bar`
99

1010
error: aborting due to previous error
1111

12-
For more information about this error, try `rustc --explain E0201`.
12+
For more information about this error, try `rustc --explain E0592`.

src/test/ui/issues/issue-77993-1.rs

-12
This file was deleted.

src/test/ui/issues/issue-77993-1.stderr

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
error[E0201]: duplicate definitions with name `bar`:
1+
error[E0592]: duplicate definitions with name `bar`
22
--> $DIR/method-macro-backtrace.rs:22:5
33
|
44
LL | fn bar(&self) { }
5-
| ------------- previous definition of `bar` here
5+
| ------------- other definition for `bar`
66
LL | fn bar(&self) { }
7-
| ^^^^^^^^^^^^^ duplicate definition
7+
| ^^^^^^^^^^^^^ duplicate definitions for `bar`
88

99
error: aborting due to previous error
1010

11-
For more information about this error, try `rustc --explain E0201`.
11+
For more information about this error, try `rustc --explain E0592`.

src/tools/tidy/src/ui_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ use std::path::Path;
77

88
const ENTRY_LIMIT: usize = 1000;
99
// FIXME: The following limits should be reduced eventually.
10-
const ROOT_ENTRY_LIMIT: usize = 950;
11-
const ISSUES_ENTRY_LIMIT: usize = 2141;
10+
const ROOT_ENTRY_LIMIT: usize = 948;
11+
const ISSUES_ENTRY_LIMIT: usize = 2126;
1212

1313
fn check_entries(path: &Path, bad: &mut bool) {
1414
let dirs = walkdir::WalkDir::new(&path.join("test/ui"))

0 commit comments

Comments
 (0)