Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 8 pull requests #103048

Merged
merged 18 commits into from
Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
88bb4e4
impl AsFd for io::{Stdin, Stdout, Stderr}, not the sys versions
joshtriplett Oct 9, 2022
ef68327
Consolidate AsFd instances for stdio types into `library/std/src/os/f…
joshtriplett Oct 10, 2022
202ccc5
Migrate highlight style to CSS variables
GuillaumeGomez Oct 4, 2022
bca1005
Add GUI test for source code pages highlighting
GuillaumeGomez Oct 4, 2022
dbc8f51
Move some tests to more reasonable directories
c410-f3r Oct 13, 2022
5191256
fix a typo
whentojump Oct 13, 2022
112ce80
Report duplicate definition in impls with overlap check.
cjgillot Aug 13, 2022
513f699
rustdoc: remove unused CSS `.search-container > *`
notriddle Oct 13, 2022
eab41a1
Suppress irrefutable let patterns lint for prefixes in match guards
est31 Oct 13, 2022
7122aba
more dupe word typos
Rageking8 Oct 13, 2022
b03bece
Rollup merge of #102847 - joshtriplett:bugfix-impl-fd-traits-for-io-t…
Dylan-DPC Oct 14, 2022
b4906ac
Rollup merge of #102856 - cjgillot:impl-single-check, r=petrochenkov
Dylan-DPC Oct 14, 2022
20e1268
Rollup merge of #102914 - GuillaumeGomez:migrate-css-highlight-withou…
Dylan-DPC Oct 14, 2022
3017341
Rollup merge of #102938 - c410-f3r:here-we-go-again, r=petrochenkov
Dylan-DPC Oct 14, 2022
8c9ecbb
Rollup merge of #103015 - whentojump:patch, r=compiler-errors
Dylan-DPC Oct 14, 2022
77064b7
Rollup merge of #103018 - Rageking8:more-dupe-word-typos, r=TaKO8Ki
Dylan-DPC Oct 14, 2022
587b9c1
Rollup merge of #103025 - notriddle:notriddle/search-container-star, …
Dylan-DPC Oct 14, 2022
7cf09c5
Rollup merge of #103031 - est31:match_guard_irrefutable_let, r=oli-obk
Dylan-DPC Oct 14, 2022
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
== item2.ident(self.tcx).normalize_to_macros_2_0()
}

fn check_for_duplicate_items_in_impl(&self, impl_: DefId) {
let impl_items = self.tcx.associated_items(impl_);

let mut seen_items = FxHashMap::default();
for impl_item in impl_items.in_definition_order() {
let span = self.tcx.def_span(impl_item.def_id);
let ident = impl_item.ident(self.tcx);

let norm_ident = ident.normalize_to_macros_2_0();
match seen_items.entry(norm_ident) {
Entry::Occupied(entry) => {
let former = entry.get();
let mut err = struct_span_err!(
self.tcx.sess,
span,
E0592,
"duplicate definitions with name `{}`",
ident,
);
err.span_label(span, format!("duplicate definitions for `{}`", ident));
err.span_label(*former, format!("other definition for `{}`", ident));

err.emit();
}
Entry::Vacant(entry) => {
entry.insert(span);
}
}
}
}

fn check_for_common_items_in_impls(
&self,
impl1: DefId,
Expand Down Expand Up @@ -133,12 +164,6 @@ impl<'tcx> InherentOverlapChecker<'tcx> {

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

// If there is only one inherent impl block,
// there is nothing to overlap check it with
if impls.len() <= 1 {
return;
}

let overlap_mode = OverlapMode::get(self.tcx, id.def_id.to_def_id());

let impls_items = impls
Expand All @@ -152,6 +177,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
const ALLOCATING_ALGO_THRESHOLD: usize = 500;
if impls.len() < ALLOCATING_ALGO_THRESHOLD {
for (i, &(&impl1_def_id, impl_items1)) in impls_items.iter().enumerate() {
self.check_for_duplicate_items_in_impl(impl1_def_id);

for &(&impl2_def_id, impl_items2) in &impls_items[(i + 1)..] {
if self.impls_have_common_items(impl_items1, impl_items2) {
self.check_for_overlapping_inherent_impls(
Expand Down Expand Up @@ -290,6 +317,8 @@ impl<'tcx> InherentOverlapChecker<'tcx> {
impl_blocks.sort_unstable();
for (i, &impl1_items_idx) in impl_blocks.iter().enumerate() {
let &(&impl1_def_id, impl_items1) = &impls_items[impl1_items_idx];
self.check_for_duplicate_items_in_impl(impl1_def_id);

for &impl2_items_idx in impl_blocks[(i + 1)..].iter() {
let &(&impl2_def_id, impl_items2) = &impls_items[impl2_items_idx];
if self.impls_have_common_items(impl_items1, impl_items2) {
Expand Down
40 changes: 1 addition & 39 deletions compiler/rustc_hir_analysis/src/impl_wf_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@
use crate::constrained_generic_params as cgp;
use min_specialization::check_min_specialization;

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::struct_span_err;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::LocalDefId;
use rustc_middle::ty::query::Providers;
use rustc_middle::ty::{self, TyCtxt, TypeVisitable};
use rustc_span::{Span, Symbol};

use std::collections::hash_map::Entry::{Occupied, Vacant};

mod min_specialization;

/// Checks that all the type/lifetime parameters on an impl also
Expand Down Expand Up @@ -59,7 +57,6 @@ fn check_mod_impl_wf(tcx: TyCtxt<'_>, module_def_id: LocalDefId) {
for id in module.items() {
if matches!(tcx.def_kind(id.def_id), DefKind::Impl) {
enforce_impl_params_are_constrained(tcx, id.def_id.def_id);
enforce_impl_items_are_distinct(tcx, id.def_id.def_id);
if min_specialization {
check_min_specialization(tcx, id.def_id.def_id);
}
Expand Down Expand Up @@ -194,38 +191,3 @@ fn report_unused_parameter(tcx: TyCtxt<'_>, span: Span, kind: &str, name: Symbol
}
err.emit();
}

/// Enforce that we do not have two items in an impl with the same name.
fn enforce_impl_items_are_distinct(tcx: TyCtxt<'_>, impl_def_id: LocalDefId) {
if tcx.impl_trait_ref(impl_def_id).is_some() {
return;
}
let mut seen_type_items = FxHashMap::default();
let mut seen_value_items = FxHashMap::default();
for &impl_item_ref in tcx.associated_item_def_ids(impl_def_id) {
let impl_item = tcx.associated_item(impl_item_ref);
let seen_items = match impl_item.kind {
ty::AssocKind::Type => &mut seen_type_items,
_ => &mut seen_value_items,
};
let span = tcx.def_span(impl_item_ref);
let ident = impl_item.ident(tcx);
match seen_items.entry(ident.normalize_to_macros_2_0()) {
Occupied(entry) => {
let mut err = struct_span_err!(
tcx.sess,
span,
E0201,
"duplicate definitions with name `{}`:",
ident
);
err.span_label(*entry.get(), format!("previous definition of `{}` here", ident));
err.span_label(span, "duplicate definition");
err.emit();
}
Vacant(entry) => {
entry.insert(span);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0201]: duplicate definitions with name `bar`:
error[E0592]: duplicate definitions with name `bar`
--> $DIR/associated-item-duplicate-names-2.rs:5:5
|
LL | const bar: bool = true;
| --------------- previous definition of `bar` here
| --------------- other definition for `bar`
LL | fn bar() {}
| ^^^^^^^^ duplicate definition
| ^^^^^^^^ duplicate definitions for `bar`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0201`.
For more information about this error, try `rustc --explain E0592`.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ struct Foo;
impl Foo {
fn orange(&self) {}
fn orange(&self) {}
//~^ ERROR duplicate definition
//~^ ERROR duplicate definitions with name `orange` [E0592]
}

fn main() {}
11 changes: 11 additions & 0 deletions src/test/ui/associated-item/impl-duplicate-methods.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0592]: duplicate definitions with name `orange`
--> $DIR/impl-duplicate-methods.rs:5:5
|
LL | fn orange(&self) {}
| ---------------- other definition for `orange`
LL | fn orange(&self) {}
| ^^^^^^^^^^^^^^^^ duplicate definitions for `orange`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0592`.
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0201.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ struct Foo(u8);

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

trait Baz {
Expand Down
9 changes: 5 additions & 4 deletions src/test/ui/error-codes/E0201.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ LL | type Quux = u32;
LL | type Quux = u32;
| ^^^^^^^^^^^^^^^^ duplicate definition

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

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0201`.
Some errors have detailed explanations: E0201, E0592.
For more information about an error, try `rustc --explain E0201`.
11 changes: 0 additions & 11 deletions src/test/ui/impl-duplicate-methods.stderr

This file was deleted.

8 changes: 4 additions & 4 deletions src/test/ui/issues/issue-4265.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
error[E0201]: duplicate definitions with name `bar`:
error[E0592]: duplicate definitions with name `bar`
--> $DIR/issue-4265.rs:10:5
|
LL | fn bar() {
| -------- previous definition of `bar` here
| -------- other definition for `bar`
...
LL | fn bar() {
| ^^^^^^^^ duplicate definition
| ^^^^^^^^ duplicate definitions for `bar`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0201`.
For more information about this error, try `rustc --explain E0592`.
8 changes: 4 additions & 4 deletions src/test/ui/methods/method-macro-backtrace.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0201]: duplicate definitions with name `bar`:
error[E0592]: duplicate definitions with name `bar`
--> $DIR/method-macro-backtrace.rs:22:5
|
LL | fn bar(&self) { }
| ------------- previous definition of `bar` here
| ------------- other definition for `bar`
LL | fn bar(&self) { }
| ^^^^^^^^^^^^^ duplicate definition
| ^^^^^^^^^^^^^ duplicate definitions for `bar`

error: aborting due to previous error

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