Skip to content

Commit 49f39ca

Browse files
CentrilMark-Simulacrum
authored andcommitted
stash API: remove panic to fix ICE.
1 parent fff19a0 commit 49f39ca

File tree

3 files changed

+69
-14
lines changed

3 files changed

+69
-14
lines changed

src/librustc_errors/lib.rs

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -446,22 +446,12 @@ impl Handler {
446446
}
447447

448448
/// Stash a given diagnostic with the given `Span` and `StashKey` as the key for later stealing.
449-
/// If the diagnostic with this `(span, key)` already exists, this will result in an ICE.
450449
pub fn stash_diagnostic(&self, span: Span, key: StashKey, diag: Diagnostic) {
451450
let mut inner = self.inner.borrow_mut();
452-
if let Some(mut old_diag) = inner.stashed_diagnostics.insert((span, key), diag) {
453-
// We are removing a previously stashed diagnostic which should not happen.
454-
old_diag.level = Bug;
455-
old_diag.note(&format!(
456-
"{}:{}: already existing stashed diagnostic with (span = {:?}, key = {:?})",
457-
file!(),
458-
line!(),
459-
span,
460-
key
461-
));
462-
inner.emit_diag_at_span(old_diag, span);
463-
panic!(ExplicitBug);
464-
}
451+
// FIXME(Centril, #69537): Consider reintroducing panic on overwriting a stashed diagnostic
452+
// if/when we have a more robust macro-friendly replacement for `(span, key)` as a key.
453+
// See the PR for a discussion.
454+
inner.stashed_diagnostics.insert((span, key), diag);
465455
}
466456

467457
/// Steal a previously stashed diagnostic with the given `Span` and `StashKey` as the key.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
macro_rules! suite {
2+
( $( $fn:ident; )* ) => {
3+
$(
4+
const A = "A".$fn();
5+
//~^ ERROR the name `A` is defined multiple times
6+
//~| ERROR missing type for `const` item
7+
//~| ERROR the type placeholder `_` is not allowed within types
8+
)*
9+
}
10+
}
11+
12+
suite! {
13+
len;
14+
is_empty;
15+
}
16+
17+
fn main() {}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
error[E0428]: the name `A` is defined multiple times
2+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:13
3+
|
4+
LL | const A = "A".$fn();
5+
| ^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| `A` redefined here
8+
| previous definition of the value `A` here
9+
...
10+
LL | / suite! {
11+
LL | | len;
12+
LL | | is_empty;
13+
LL | | }
14+
| |_- in this macro invocation
15+
|
16+
= note: `A` must be defined only once in the value namespace of this module
17+
18+
error: missing type for `const` item
19+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
20+
|
21+
LL | const A = "A".$fn();
22+
| ^ help: provide a type for the item: `A: usize`
23+
...
24+
LL | / suite! {
25+
LL | | len;
26+
LL | | is_empty;
27+
LL | | }
28+
| |_- in this macro invocation
29+
30+
error[E0121]: the type placeholder `_` is not allowed within types on item signatures
31+
--> $DIR/issue-69396-const-no-type-in-macro.rs:4:19
32+
|
33+
LL | const A = "A".$fn();
34+
| ^
35+
| |
36+
| not allowed in type signatures
37+
| help: replace `_` with the correct type: `bool`
38+
...
39+
LL | / suite! {
40+
LL | | len;
41+
LL | | is_empty;
42+
LL | | }
43+
| |_- in this macro invocation
44+
45+
error: aborting due to 3 previous errors
46+
47+
Some errors have detailed explanations: E0121, E0428.
48+
For more information about an error, try `rustc --explain E0121`.

0 commit comments

Comments
 (0)