Skip to content

Commit 4222100

Browse files
committed
Accept inconsistent macro resolution for #147319 workaround
1 parent c78702a commit 4222100

File tree

3 files changed

+87
-4
lines changed

3 files changed

+87
-4
lines changed

compiler/rustc_resolve/src/macros.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -838,10 +838,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
838838
res: Res| {
839839
if let Some(initial_res) = initial_res {
840840
if res != initial_res {
841-
// Make sure compilation does not succeed if preferred macro resolution
842-
// has changed after the macro had been expanded. In theory all such
843-
// situations should be reported as errors, so this is a bug.
844-
this.dcx().span_delayed_bug(span, "inconsistent resolution for a macro");
841+
// Delayed versions of the #147319 workaround are inconsistent, but not really
842+
// problematic and already seen as a bug.
843+
// FIXME: Remove with lang team approval.
844+
if !this
845+
.ambiguity_errors
846+
.iter()
847+
.all(|ambiguity_error| ambiguity_error.warning.is_some())
848+
{
849+
// Make sure compilation does not succeed if preferred macro resolution
850+
// has changed after the macro had been expanded. In theory all such
851+
// situations should be reported as errors, so this is a bug.
852+
this.dcx().span_delayed_bug(span, "inconsistent resolution for a macro");
853+
}
845854
}
846855
} else if this.tcx.dcx().has_errors().is_none() && this.privacy_errors.is_empty() {
847856
// It's possible that the macro was unresolved (indeterminate) and silently
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![crate_type = "lib"]
2+
#![no_std]
3+
4+
macro_rules! re_emit {
5+
($($i:item)*) => ($($i)*)
6+
}
7+
8+
// By re-emitting the prelude import via a macro, we run into the delayed bugs code path.
9+
re_emit! {
10+
extern crate std;
11+
use std::prelude::v1::*;
12+
}
13+
14+
#[allow(unused)]
15+
fn xx() {
16+
panic!();
17+
//~^ WARNING `panic` is ambiguous
18+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
19+
20+
// We can't deny the above lint, or else it *won't* run into the problematic issue of *not*
21+
// having reported an error. So we crate a dummy error.
22+
let _ = unknown_item;
23+
//~^ ERROR: cannot find value `unknown_item`
24+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
error[E0425]: cannot find value `unknown_item` in this scope
2+
--> $DIR/ambiguous-panic-re-emit.rs:22:13
3+
|
4+
LL | let _ = unknown_item;
5+
| ^^^^^^^^^^^^ not found in this scope
6+
7+
warning: `panic` is ambiguous
8+
--> $DIR/ambiguous-panic-re-emit.rs:16:5
9+
|
10+
LL | panic!();
11+
| ^^^^^ ambiguous name
12+
|
13+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
14+
= note: for more information, see issue #147319 <https://github.com/rust-lang/rust/issues/147319>
15+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
16+
note: `panic` could refer to the macro imported here
17+
--> $DIR/ambiguous-panic-re-emit.rs:11:9
18+
|
19+
LL | use std::prelude::v1::*;
20+
| ^^^^^^^^^^^^^^^^^^^
21+
= help: consider adding an explicit import of `panic` to disambiguate
22+
= help: or use `crate::panic` to refer to this macro unambiguously
23+
note: `panic` could also refer to a macro from prelude
24+
--> $SRC_DIR/core/src/prelude/mod.rs:LL:COL
25+
= note: `#[warn(ambiguous_panic_imports)]` (part of `#[warn(future_incompatible)]`) on by default
26+
27+
error: aborting due to 1 previous error; 1 warning emitted
28+
29+
For more information about this error, try `rustc --explain E0425`.
30+
Future incompatibility report: Future breakage diagnostic:
31+
warning: `panic` is ambiguous
32+
--> $DIR/ambiguous-panic-re-emit.rs:16:5
33+
|
34+
LL | panic!();
35+
| ^^^^^ ambiguous name
36+
|
37+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
38+
= note: for more information, see issue #147319 <https://github.com/rust-lang/rust/issues/147319>
39+
= note: ambiguous because of a conflict between a name from a glob import and an outer scope during import or macro resolution
40+
note: `panic` could refer to the macro imported here
41+
--> $DIR/ambiguous-panic-re-emit.rs:11:9
42+
|
43+
LL | use std::prelude::v1::*;
44+
| ^^^^^^^^^^^^^^^^^^^
45+
= help: consider adding an explicit import of `panic` to disambiguate
46+
= help: or use `crate::panic` to refer to this macro unambiguously
47+
note: `panic` could also refer to a macro from prelude
48+
--> $SRC_DIR/core/src/prelude/mod.rs:LL:COL
49+
= note: `#[warn(ambiguous_panic_imports)]` (part of `#[warn(future_incompatible)]`) on by default
50+

0 commit comments

Comments
 (0)