mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
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.
This commit is contained in:
@@ -212,12 +212,12 @@ pub(crate) fn report_conflict(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
ns: Namespace,
|
||||
new_binding: Decl<'ra>,
|
||||
old_binding: Decl<'ra>,
|
||||
new_binding: Decl<'ra>,
|
||||
) {
|
||||
// Error on the second of two conflicting names
|
||||
if old_binding.span.lo() > new_binding.span.lo() {
|
||||
return self.report_conflict(ident, ns, old_binding, new_binding);
|
||||
return self.report_conflict(ident, ns, new_binding, old_binding);
|
||||
}
|
||||
|
||||
let container = match old_binding.parent_module.unwrap().kind {
|
||||
|
||||
@@ -348,8 +348,8 @@ pub(crate) fn new_import_decl(&self, decl: Decl<'ra>, import: Import<'ra>) -> De
|
||||
/// decide which one to keep.
|
||||
fn select_glob_decl(
|
||||
&self,
|
||||
glob_decl: Decl<'ra>,
|
||||
old_glob_decl: Decl<'ra>,
|
||||
glob_decl: Decl<'ra>,
|
||||
warn_ambiguity: bool,
|
||||
) -> Decl<'ra> {
|
||||
assert!(glob_decl.is_glob_import());
|
||||
@@ -369,7 +369,7 @@ fn select_glob_decl(
|
||||
// with the re-fetched decls.
|
||||
// This is probably incorrect in corner cases, and the outdated decls still get
|
||||
// propagated to other places and get stuck there, but that's what we have at the moment.
|
||||
let (deep_decl, old_deep_decl) = remove_same_import(glob_decl, old_glob_decl);
|
||||
let (old_deep_decl, deep_decl) = remove_same_import(old_glob_decl, glob_decl);
|
||||
if deep_decl != glob_decl {
|
||||
// Some import layers have been removed, need to overwrite.
|
||||
assert_ne!(old_deep_decl, old_glob_decl);
|
||||
@@ -436,7 +436,7 @@ pub(crate) fn try_plant_decl_into_local_module(
|
||||
match (old_decl.is_glob_import(), decl.is_glob_import()) {
|
||||
(true, true) => {
|
||||
resolution.glob_decl =
|
||||
Some(this.select_glob_decl(decl, old_decl, warn_ambiguity));
|
||||
Some(this.select_glob_decl(old_decl, decl, warn_ambiguity));
|
||||
}
|
||||
(old_glob @ true, false) | (old_glob @ false, true) => {
|
||||
let (glob_decl, non_glob_decl) =
|
||||
@@ -446,7 +446,7 @@ pub(crate) fn try_plant_decl_into_local_module(
|
||||
&& old_glob_decl != glob_decl
|
||||
{
|
||||
resolution.glob_decl =
|
||||
Some(this.select_glob_decl(glob_decl, old_glob_decl, false));
|
||||
Some(this.select_glob_decl(old_glob_decl, glob_decl, false));
|
||||
} else {
|
||||
resolution.glob_decl = Some(glob_decl);
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
use use_by_macro::*;
|
||||
|
||||
my_struct!(define);
|
||||
//~^ ERROR the name `MyStruct` is defined multiple times
|
||||
my_struct!(define);
|
||||
//~^ ERROR the name `MyStruct` is defined multiple times
|
||||
|
||||
fn main() {}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
error[E0428]: the name `MyStruct` is defined multiple times
|
||||
--> $DIR/cross-crate-redefine.rs:10:1
|
||||
--> $DIR/cross-crate-redefine.rs:11:1
|
||||
|
|
||||
LL | my_struct!(define);
|
||||
| ^^^^^^^^^^^^^^^^^^ `MyStruct` redefined here
|
||||
LL |
|
||||
LL | my_struct!(define);
|
||||
| ------------------ previous definition of the type `MyStruct` here
|
||||
LL | my_struct!(define);
|
||||
| ^^^^^^^^^^^^^^^^^^ `MyStruct` redefined here
|
||||
|
|
||||
= note: `MyStruct` must be defined only once in the type namespace of this module
|
||||
= note: this error originates in the macro `my_struct` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
|
||||
Reference in New Issue
Block a user