Skip to content

Commit 2c96087

Browse files
committed
add test case for #89566
1 parent f6ec648 commit 2c96087

4 files changed

+28
-2
lines changed

compiler/rustc_resolve/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
702702
for attr in attrs.iter().filter(|attr| attr.style == AttrStyle::Inner) {
703703
if attr.has_name(name) {
704704
let tcx = self.tcx;
705-
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
705+
tcx.dcx().emit_err(errors::InvalidAttrAtCrateLevel {
706706
name,
707707
span: attr.span,
708708
sugg: errors::InvalidAttrSugg {
@@ -761,7 +761,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
761761
fallback =
762762
!this.report_invalid_crate_level_attr(&krate.attrs, path[0].ident.name);
763763
}
764-
if fallback && this.tcx.sess.has_errors().is_none() {
764+
if fallback && this.tcx.dcx().has_errors().is_none() {
765765
this.dcx().emit_err(CannotDetermineMacroResolution {
766766
span,
767767
kind: kind.descr(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-rustfix
2+
3+
#[derive(Debug)] //~ ERROR `derive` attribute cannot be used at crate level
4+
struct Test {}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// run-rustfix
2+
3+
#![derive(Debug)] //~ ERROR `derive` attribute cannot be used at crate level
4+
struct Test {}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: `derive` attribute cannot be used at crate level
2+
--> $DIR/issue-89566-suggest-fix-invalid-top-level-macro-attr.rs:3:1
3+
|
4+
LL | #![derive(Debug)]
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
help: perhaps you meant to use an outer attribute
8+
|
9+
LL - #![derive(Debug)]
10+
LL + #[derive(Debug)]
11+
|
12+
13+
error: aborting due to 1 previous error
14+

0 commit comments

Comments
 (0)