Skip to content

Commit 81ef42d

Browse files
committed
resolve: Consistently use old decls before new decls in interfaces
The opposite ordering was a consistent source of confusion during debuggingю `report_conflict` actually used an incorrect order due to similar confusion.
1 parent 8b52c73 commit 81ef42d

4 files changed

Lines changed: 10 additions & 11 deletions

File tree

compiler/rustc_resolve/src/diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,12 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
212212
&mut self,
213213
ident: Ident,
214214
ns: Namespace,
215-
new_binding: Decl<'ra>,
216215
old_binding: Decl<'ra>,
216+
new_binding: Decl<'ra>,
217217
) {
218218
// Error on the second of two conflicting names
219219
if old_binding.span.lo() > new_binding.span.lo() {
220-
return self.report_conflict(ident, ns, old_binding, new_binding);
220+
return self.report_conflict(ident, ns, new_binding, old_binding);
221221
}
222222

223223
let container = match old_binding.parent_module.unwrap().kind {

compiler/rustc_resolve/src/imports.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,8 +348,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
348348
/// decide which one to keep.
349349
fn select_glob_decl(
350350
&self,
351-
glob_decl: Decl<'ra>,
352351
old_glob_decl: Decl<'ra>,
352+
glob_decl: Decl<'ra>,
353353
warn_ambiguity: bool,
354354
) -> Decl<'ra> {
355355
assert!(glob_decl.is_glob_import());
@@ -369,7 +369,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
369369
// with the re-fetched decls.
370370
// This is probably incorrect in corner cases, and the outdated decls still get
371371
// propagated to other places and get stuck there, but that's what we have at the moment.
372-
let (deep_decl, old_deep_decl) = remove_same_import(glob_decl, old_glob_decl);
372+
let (old_deep_decl, deep_decl) = remove_same_import(old_glob_decl, glob_decl);
373373
if deep_decl != glob_decl {
374374
// Some import layers have been removed, need to overwrite.
375375
assert_ne!(old_deep_decl, old_glob_decl);
@@ -436,7 +436,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
436436
match (old_decl.is_glob_import(), decl.is_glob_import()) {
437437
(true, true) => {
438438
resolution.glob_decl =
439-
Some(this.select_glob_decl(decl, old_decl, warn_ambiguity));
439+
Some(this.select_glob_decl(old_decl, decl, warn_ambiguity));
440440
}
441441
(old_glob @ true, false) | (old_glob @ false, true) => {
442442
let (glob_decl, non_glob_decl) =
@@ -446,7 +446,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
446446
&& old_glob_decl != glob_decl
447447
{
448448
resolution.glob_decl =
449-
Some(this.select_glob_decl(glob_decl, old_glob_decl, false));
449+
Some(this.select_glob_decl(old_glob_decl, glob_decl, false));
450450
} else {
451451
resolution.glob_decl = Some(glob_decl);
452452
}

tests/ui/hygiene/cross-crate-redefine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ extern crate use_by_macro;
88
use use_by_macro::*;
99

1010
my_struct!(define);
11-
//~^ ERROR the name `MyStruct` is defined multiple times
1211
my_struct!(define);
12+
//~^ ERROR the name `MyStruct` is defined multiple times
1313

1414
fn main() {}

tests/ui/hygiene/cross-crate-redefine.stderr

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
error[E0428]: the name `MyStruct` is defined multiple times
2-
--> $DIR/cross-crate-redefine.rs:10:1
2+
--> $DIR/cross-crate-redefine.rs:11:1
33
|
4-
LL | my_struct!(define);
5-
| ^^^^^^^^^^^^^^^^^^ `MyStruct` redefined here
6-
LL |
74
LL | my_struct!(define);
85
| ------------------ previous definition of the type `MyStruct` here
6+
LL | my_struct!(define);
7+
| ^^^^^^^^^^^^^^^^^^ `MyStruct` redefined here
98
|
109
= note: `MyStruct` must be defined only once in the type namespace of this module
1110
= note: this error originates in the macro `my_struct` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)