about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2023-05-04 00:17:25 +0530
committerGitHub <noreply@github.com>2023-05-04 00:17:25 +0530
commitfce0741fe9a3c6904608dd04ef8a25d8ceb6ca35 (patch)
treebad2964aa31977881d23f86950aa92c66f4c2960
parent8b7080b15bc2846ba547a9086ae1b3df8a69d2d1 (diff)
parent0453cda59e4eb09e2bc632c41420da22bfeac242 (diff)
downloadrust-fce0741fe9a3c6904608dd04ef8a25d8ceb6ca35.tar.gz
rust-fce0741fe9a3c6904608dd04ef8a25d8ceb6ca35.zip
Rollup merge of #111062 - clubby789:invalid-repr-unchecked, r=petrochenkov
Don't bail out early when checking invalid `repr` attr

Fixes #111051

An invalid repr delays a bug. If there are other invalid attributes on the item, we emit a warning and exit without re-checking the repr here, so no error is emitted and the delayed bug ICEs
-rw-r--r--compiler/rustc_passes/src/check_attr.rs8
-rw-r--r--tests/ui/repr/invalid_repr_list_help.rs5
-rw-r--r--tests/ui/repr/invalid_repr_list_help.stderr20
3 files changed, 25 insertions, 8 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 3f28ac26f86..06aa2737915 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -101,12 +101,11 @@ impl CheckAttrVisitor<'_> {
         item: Option<ItemLike<'_>>,
     ) {
         let mut doc_aliases = FxHashMap::default();
-        let mut is_valid = true;
         let mut specified_inline = None;
         let mut seen = FxHashMap::default();
         let attrs = self.tcx.hir().attrs(hir_id);
         for attr in attrs {
-            let attr_is_valid = match attr.name_or_empty() {
+            match attr.name_or_empty() {
                 sym::do_not_recommend => self.check_do_not_recommend(attr.span, target),
                 sym::inline => self.check_inline(hir_id, attr, span, target),
                 sym::no_coverage => self.check_no_coverage(hir_id, attr, span, target),
@@ -188,7 +187,6 @@ impl CheckAttrVisitor<'_> {
                 sym::link_ordinal => self.check_link_ordinal(&attr, span, target),
                 _ => true,
             };
-            is_valid &= attr_is_valid;
 
             // lint-only checks
             match attr.name_or_empty() {
@@ -255,10 +253,6 @@ impl CheckAttrVisitor<'_> {
             self.check_unused_attribute(hir_id, attr)
         }
 
-        if !is_valid {
-            return;
-        }
-
         self.check_repr(attrs, span, target, item, hir_id);
         self.check_used(attrs, target);
     }
diff --git a/tests/ui/repr/invalid_repr_list_help.rs b/tests/ui/repr/invalid_repr_list_help.rs
index c320984536c..785ffb1e0f4 100644
--- a/tests/ui/repr/invalid_repr_list_help.rs
+++ b/tests/ui/repr/invalid_repr_list_help.rs
@@ -15,3 +15,8 @@ pub struct OwO3 {
 pub enum OwO4 {
     UwU = 1,
 }
+
+#[repr(uwu)] //~ERROR: unrecognized representation hint
+#[doc(owo)]  //~WARN: unknown `doc` attribute
+             //~^ WARN: this was previously
+pub struct Owo5;
diff --git a/tests/ui/repr/invalid_repr_list_help.stderr b/tests/ui/repr/invalid_repr_list_help.stderr
index 2acd56d9a32..48a6af3dd4c 100644
--- a/tests/ui/repr/invalid_repr_list_help.stderr
+++ b/tests/ui/repr/invalid_repr_list_help.stderr
@@ -30,6 +30,24 @@ LL | #[repr(uwu, u8)]
    |
    = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
 
-error: aborting due to 4 previous errors
+warning: unknown `doc` attribute `owo`
+  --> $DIR/invalid_repr_list_help.rs:20:7
+   |
+LL | #[doc(owo)]
+   |       ^^^
+   |
+   = warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
+   = note: for more information, see issue #82730 <https://github.com/rust-lang/rust/issues/82730>
+   = note: `#[warn(invalid_doc_attributes)]` on by default
+
+error[E0552]: unrecognized representation hint
+  --> $DIR/invalid_repr_list_help.rs:19:8
+   |
+LL | #[repr(uwu)]
+   |        ^^^
+   |
+   = help: valid reprs are `C`, `align`, `packed`, `transparent`, `simd`, `i8`, `u8`, `i16`, `u16`, `i32`, `u32`, `i64`, `u64`, `i128`, `u128`, `isize`, `usize`
+
+error: aborting due to 5 previous errors; 1 warning emitted
 
 For more information about this error, try `rustc --explain E0552`.