Skip to content

Commit 2c55bac

Browse files
authored
Rollup merge of #83634 - JohnTitor:proc-macro-ice, r=varkor
Do not emit the advanced diagnostics on macros Fixes #83510
2 parents 505846e + 960b699 commit 2c55bac

File tree

4 files changed

+71
-1
lines changed

4 files changed

+71
-1
lines changed

compiler/rustc_resolve/src/late/diagnostics.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -456,12 +456,14 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
456456
}
457457
}
458458

459+
let is_macro = base_span.from_expansion() && base_span.desugaring_kind().is_none();
459460
if !self.type_ascription_suggestion(&mut err, base_span) {
460461
let mut fallback = false;
461462
if let (
462463
PathSource::Trait(AliasPossibility::Maybe),
463464
Some(Res::Def(DefKind::Struct | DefKind::Enum | DefKind::Union, _)),
464-
) = (source, res)
465+
false,
466+
) = (source, res, is_macro)
465467
{
466468
if let Some(bounds @ [_, .., _]) = self.diagnostic_metadata.current_trait_object {
467469
fallback = true;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
#[proc_macro]
11+
pub fn dance_like_you_want_to_ice(_: TokenStream) -> TokenStream {
12+
r#"
13+
impl Foo {
14+
type Bar = Box<()> + Baz;
15+
}
16+
"#
17+
.parse()
18+
.unwrap()
19+
}

src/test/ui/proc-macro/issue-83510.rs

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// aux-build: issue-83510.rs
2+
3+
extern crate issue_83510;
4+
5+
issue_83510::dance_like_you_want_to_ice!();
6+
//~^ ERROR: cannot find type `Foo` in this scope
7+
//~| ERROR: expected trait, found struct `Box`
8+
//~| ERROR: cannot find trait `Baz` in this scope
9+
//~| ERROR: inherent associated types are unstable
10+
11+
fn main() {}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
error[E0412]: cannot find type `Foo` in this scope
2+
--> $DIR/issue-83510.rs:5:1
3+
|
4+
LL | issue_83510::dance_like_you_want_to_ice!();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
6+
|
7+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error[E0404]: expected trait, found struct `Box`
10+
--> $DIR/issue-83510.rs:5:1
11+
|
12+
LL | issue_83510::dance_like_you_want_to_ice!();
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not a trait
14+
|
15+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
16+
17+
error[E0405]: cannot find trait `Baz` in this scope
18+
--> $DIR/issue-83510.rs:5:1
19+
|
20+
LL | issue_83510::dance_like_you_want_to_ice!();
21+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ not found in this scope
22+
|
23+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
24+
25+
error[E0658]: inherent associated types are unstable
26+
--> $DIR/issue-83510.rs:5:1
27+
|
28+
LL | issue_83510::dance_like_you_want_to_ice!();
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: see issue #8995 <https://github.com/rust-lang/rust/issues/8995> for more information
32+
= help: add `#![feature(inherent_associated_types)]` to the crate attributes to enable
33+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
34+
35+
error: aborting due to 4 previous errors
36+
37+
Some errors have detailed explanations: E0404, E0405, E0412, E0658.
38+
For more information about an error, try `rustc --explain E0404`.

0 commit comments

Comments
 (0)