Skip to content

Commit

Permalink
add test case for #89566
Browse files Browse the repository at this point in the history
  • Loading branch information
chenyukang committed Jan 4, 2024
1 parent f6ec648 commit 2c96087
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
for attr in attrs.iter().filter(|attr| attr.style == AttrStyle::Inner) {
if attr.has_name(name) {
let tcx = self.tcx;
tcx.sess.emit_err(errors::InvalidAttrAtCrateLevel {
tcx.dcx().emit_err(errors::InvalidAttrAtCrateLevel {
name,
span: attr.span,
sugg: errors::InvalidAttrSugg {
Expand Down Expand Up @@ -761,7 +761,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
fallback =
!this.report_invalid_crate_level_attr(&krate.attrs, path[0].ident.name);
}
if fallback && this.tcx.sess.has_errors().is_none() {
if fallback && this.tcx.dcx().has_errors().is_none() {
this.dcx().emit_err(CannotDetermineMacroResolution {
span,
kind: kind.descr(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-rustfix

#[derive(Debug)] //~ ERROR `derive` attribute cannot be used at crate level
struct Test {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// run-rustfix

#![derive(Debug)] //~ ERROR `derive` attribute cannot be used at crate level
struct Test {}

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
error: `derive` attribute cannot be used at crate level
--> $DIR/issue-89566-suggest-fix-invalid-top-level-macro-attr.rs:3:1
|
LL | #![derive(Debug)]
| ^^^^^^^^^^^^^^^^^
|
help: perhaps you meant to use an outer attribute
|
LL - #![derive(Debug)]
LL + #[derive(Debug)]
|

error: aborting due to 1 previous error

0 comments on commit 2c96087

Please sign in to comment.