about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2022-11-06 16:28:07 +0000
committerCamille GILLOT <gillot.camille@gmail.com>2022-11-13 14:02:15 +0000
commitdba1503ed3c364f388128d42633ba00258ffad49 (patch)
tree139f6c98213bbba7a495da14114555775e6f8e31
parent928d14bcd1976ffd33e743aa09c7c22a063bf87c (diff)
downloadrust-dba1503ed3c364f388128d42633ba00258ffad49.tar.gz
rust-dba1503ed3c364f388128d42633ba00258ffad49.zip
Ensure codegen_fn_attrs during collection.
-rw-r--r--compiler/rustc_hir_analysis/src/collect.rs10
-rw-r--r--compiler/rustc_passes/src/check_attr.rs12
-rw-r--r--src/test/ui/lang-items/lang-item-generic-requirements.rs2
-rw-r--r--src/test/ui/lang-items/lang-item-generic-requirements.stderr27
-rw-r--r--src/test/ui/macros/issue-68060.rs4
-rw-r--r--src/test/ui/macros/issue-68060.stderr18
-rw-r--r--src/test/ui/panic-handler/panic-handler-std.stderr8
-rw-r--r--src/test/ui/range/issue-54505-no-std.rs6
-rw-r--r--src/test/ui/range/issue-54505-no-std.stderr38
-rw-r--r--src/test/ui/target-feature/invalid-attribute.stderr72
-rw-r--r--src/test/ui/traits/issue-102989.rs4
-rw-r--r--src/test/ui/traits/issue-102989.stderr31
12 files changed, 103 insertions, 129 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs
index 0e7a5ebf5ab..0f8d4e9654a 100644
--- a/compiler/rustc_hir_analysis/src/collect.rs
+++ b/compiler/rustc_hir_analysis/src/collect.rs
@@ -314,6 +314,7 @@ impl<'tcx> Visitor<'tcx> for CollectItemTypesVisitor<'tcx> {
         if let hir::ExprKind::Closure { .. } = expr.kind {
             let def_id = self.tcx.hir().local_def_id(expr.hir_id);
             self.tcx.ensure().generics_of(def_id);
+            self.tcx.ensure().codegen_fn_attrs(def_id);
             // We do not call `type_of` for closures here as that
             // depends on typecheck and would therefore hide
             // any further errors in case one typeck fails.
@@ -586,8 +587,12 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
                 tcx.ensure().type_of(item.owner_id);
                 tcx.ensure().predicates_of(item.owner_id);
                 match item.kind {
-                    hir::ForeignItemKind::Fn(..) => tcx.ensure().fn_sig(item.owner_id),
+                    hir::ForeignItemKind::Fn(..) => {
+                        tcx.ensure().codegen_fn_attrs(item.owner_id);
+                        tcx.ensure().fn_sig(item.owner_id)
+                    }
                     hir::ForeignItemKind::Static(..) => {
+                        tcx.ensure().codegen_fn_attrs(item.owner_id);
                         let mut visitor = HirPlaceholderCollector::default();
                         visitor.visit_foreign_item(item);
                         placeholder_type_error(
@@ -676,6 +681,7 @@ fn convert_item(tcx: TyCtxt<'_>, item_id: hir::ItemId) {
             tcx.ensure().type_of(def_id);
             tcx.ensure().predicates_of(def_id);
             tcx.ensure().fn_sig(def_id);
+            tcx.ensure().codegen_fn_attrs(def_id);
         }
     }
 }
@@ -687,6 +693,7 @@ fn convert_trait_item(tcx: TyCtxt<'_>, trait_item_id: hir::TraitItemId) {
 
     match trait_item.kind {
         hir::TraitItemKind::Fn(..) => {
+            tcx.ensure().codegen_fn_attrs(def_id);
             tcx.ensure().type_of(def_id);
             tcx.ensure().fn_sig(def_id);
         }
@@ -736,6 +743,7 @@ fn convert_impl_item(tcx: TyCtxt<'_>, impl_item_id: hir::ImplItemId) {
     let impl_item = tcx.hir().impl_item(impl_item_id);
     match impl_item.kind {
         hir::ImplItemKind::Fn(..) => {
+            tcx.ensure().codegen_fn_attrs(def_id);
             tcx.ensure().fn_sig(def_id);
         }
         hir::ImplItemKind::Type(_) => {
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index 2b6ff0a5cb9..f3fc26e4784 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -219,18 +219,6 @@ impl CheckAttrVisitor<'_> {
             return;
         }
 
-        // FIXME(@lcnr): this doesn't belong here.
-        if matches!(
-            target,
-            Target::Closure
-                | Target::Fn
-                | Target::Method(_)
-                | Target::ForeignFn
-                | Target::ForeignStatic
-        ) {
-            self.tcx.ensure().codegen_fn_attrs(self.tcx.hir().local_def_id(hir_id));
-        }
-
         self.check_repr(attrs, span, target, item, hir_id);
         self.check_used(attrs, target);
     }
diff --git a/src/test/ui/lang-items/lang-item-generic-requirements.rs b/src/test/ui/lang-items/lang-item-generic-requirements.rs
index fbb56e528c0..3d33adf6831 100644
--- a/src/test/ui/lang-items/lang-item-generic-requirements.rs
+++ b/src/test/ui/lang-items/lang-item-generic-requirements.rs
@@ -22,8 +22,6 @@ trait MyIndex<'a, T> {}
 #[lang = "phantom_data"]
 //~^ ERROR `phantom_data` language item must be applied to a struct with 1 generic argument
 struct MyPhantomData<T, U>;
-//~^ ERROR parameter `T` is never used
-//~| ERROR parameter `U` is never used
 
 #[lang = "owned_box"]
 //~^ ERROR `owned_box` language item must be applied to a struct with at least 1 generic argument
diff --git a/src/test/ui/lang-items/lang-item-generic-requirements.stderr b/src/test/ui/lang-items/lang-item-generic-requirements.stderr
index 326f5b0d595..4d349a25f9c 100644
--- a/src/test/ui/lang-items/lang-item-generic-requirements.stderr
+++ b/src/test/ui/lang-items/lang-item-generic-requirements.stderr
@@ -33,7 +33,7 @@ LL | struct MyPhantomData<T, U>;
    |                     ------ this struct has 2 generic arguments
 
 error[E0718]: `owned_box` language item must be applied to a struct with at least 1 generic argument
-  --> $DIR/lang-item-generic-requirements.rs:28:1
+  --> $DIR/lang-item-generic-requirements.rs:26:1
    |
 LL | #[lang = "owned_box"]
    | ^^^^^^^^^^^^^^^^^^^^^
@@ -42,7 +42,7 @@ LL | struct Foo;
    |           - this struct has 0 generic arguments
 
 error[E0718]: `start` language item must be applied to a function with 1 generic argument
-  --> $DIR/lang-item-generic-requirements.rs:34:1
+  --> $DIR/lang-item-generic-requirements.rs:32:1
    |
 LL | #[lang = "start"]
    | ^^^^^^^^^^^^^^^^^
@@ -50,25 +50,6 @@ LL |
 LL | fn start(_: *const u8, _: isize, _: *const *const u8) -> isize {
    |         - this function has 0 generic arguments
 
-error[E0392]: parameter `T` is never used
-  --> $DIR/lang-item-generic-requirements.rs:24:22
-   |
-LL | struct MyPhantomData<T, U>;
-   |                      ^ unused parameter
-   |
-   = help: consider removing `T` or referring to it in a field
-   = help: if you intended `T` to be a const parameter, use `const T: usize` instead
-
-error[E0392]: parameter `U` is never used
-  --> $DIR/lang-item-generic-requirements.rs:24:25
-   |
-LL | struct MyPhantomData<T, U>;
-   |                         ^ unused parameter
-   |
-   = help: consider removing `U` or referring to it in a field
-   = help: if you intended `U` to be a const parameter, use `const U: usize` instead
-
-error: aborting due to 8 previous errors
+error: aborting due to 6 previous errors
 
-Some errors have detailed explanations: E0392, E0718.
-For more information about an error, try `rustc --explain E0392`.
+For more information about this error, try `rustc --explain E0718`.
diff --git a/src/test/ui/macros/issue-68060.rs b/src/test/ui/macros/issue-68060.rs
index aa8f578adf6..fb40cd5387b 100644
--- a/src/test/ui/macros/issue-68060.rs
+++ b/src/test/ui/macros/issue-68060.rs
@@ -3,7 +3,11 @@ fn main() {
         .map(
             #[target_feature(enable = "")]
             //~^ ERROR: attribute should be applied to a function
+            //~| ERROR: feature named `` is not valid
+            //~| NOTE: `` is not valid for this target
             #[track_caller]
+            //~^ ERROR: `#[track_caller]` on closures is currently unstable
+            //~| NOTE: see issue #87417
             |_| (),
             //~^ NOTE: not a function
         )
diff --git a/src/test/ui/macros/issue-68060.stderr b/src/test/ui/macros/issue-68060.stderr
index b13e418e664..52e6ed92e9d 100644
--- a/src/test/ui/macros/issue-68060.stderr
+++ b/src/test/ui/macros/issue-68060.stderr
@@ -7,5 +7,21 @@ LL |             #[target_feature(enable = "")]
 LL |             |_| (),
    |             ------ not a function definition
 
-error: aborting due to previous error
+error: the feature named `` is not valid for this target
+  --> $DIR/issue-68060.rs:4:30
+   |
+LL |             #[target_feature(enable = "")]
+   |                              ^^^^^^^^^^^ `` is not valid for this target
+
+error[E0658]: `#[track_caller]` on closures is currently unstable
+  --> $DIR/issue-68060.rs:8:13
+   |
+LL |             #[track_caller]
+   |             ^^^^^^^^^^^^^^^
+   |
+   = note: see issue #87417 <https://github.com/rust-lang/rust/issues/87417> for more information
+   = help: add `#![feature(closure_track_caller)]` to the crate attributes to enable
+
+error: aborting due to 3 previous errors
 
+For more information about this error, try `rustc --explain E0658`.
diff --git a/src/test/ui/panic-handler/panic-handler-std.stderr b/src/test/ui/panic-handler/panic-handler-std.stderr
index e4069b196ff..7c7feffe76a 100644
--- a/src/test/ui/panic-handler/panic-handler-std.stderr
+++ b/src/test/ui/panic-handler/panic-handler-std.stderr
@@ -8,12 +8,6 @@ LL | fn panic(info: PanicInfo) -> ! {
    = note: first definition in `std` loaded from SYSROOT/libstd-*.rlib
    = note: second definition in the local crate (`panic_handler_std`)
 
-error: argument should be `&PanicInfo`
-  --> $DIR/panic-handler-std.rs:8:16
-   |
-LL | fn panic(info: PanicInfo) -> ! {
-   |                ^^^^^^^^^
-
-error: aborting due to 2 previous errors
+error: aborting due to previous error
 
 For more information about this error, try `rustc --explain E0152`.
diff --git a/src/test/ui/range/issue-54505-no-std.rs b/src/test/ui/range/issue-54505-no-std.rs
index ab1a025b521..9f378b4836e 100644
--- a/src/test/ui/range/issue-54505-no-std.rs
+++ b/src/test/ui/range/issue-54505-no-std.rs
@@ -1,5 +1,3 @@
-// error-pattern: `#[panic_handler]` function required, but not found
-
 // Regression test for #54505 - range borrowing suggestion had
 // incorrect syntax (missing parentheses).
 
@@ -18,6 +16,10 @@ extern "C" fn eh_personality() {}
 #[lang = "eh_catch_typeinfo"]
 static EH_CATCH_TYPEINFO: u8 = 0;
 
+#[panic_handler]
+fn panic_handler() {}
+//~^ ERROR return type should be `!`
+//~| ERROR function should have one argument
 
 // take a reference to any built-in range
 fn take_range(_r: &impl RangeBounds<i8>) {}
diff --git a/src/test/ui/range/issue-54505-no-std.stderr b/src/test/ui/range/issue-54505-no-std.stderr
index c4e36b0b159..9fb0e54a8a9 100644
--- a/src/test/ui/range/issue-54505-no-std.stderr
+++ b/src/test/ui/range/issue-54505-no-std.stderr
@@ -1,7 +1,17 @@
-error: `#[panic_handler]` function required, but not found
+error: return type should be `!`
+  --> $DIR/issue-54505-no-std.rs:20:20
+   |
+LL | fn panic_handler() {}
+   |                    ^
+
+error: function should have one argument
+  --> $DIR/issue-54505-no-std.rs:20:1
+   |
+LL | fn panic_handler() {}
+   | ^^^^^^^^^^^^^^^^^^
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:27:16
+  --> $DIR/issue-54505-no-std.rs:29:16
    |
 LL |     take_range(0..1);
    |     ---------- ^^^^
@@ -13,13 +23,13 @@ LL |     take_range(0..1);
    = note: expected reference `&_`
                  found struct `Range<{integer}>`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:32:16
+  --> $DIR/issue-54505-no-std.rs:34:16
    |
 LL |     take_range(1..);
    |     ---------- ^^^
@@ -31,13 +41,13 @@ LL |     take_range(1..);
    = note: expected reference `&_`
                  found struct `RangeFrom<{integer}>`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:37:16
+  --> $DIR/issue-54505-no-std.rs:39:16
    |
 LL |     take_range(..);
    |     ---------- ^^
@@ -49,13 +59,13 @@ LL |     take_range(..);
    = note: expected reference `&_`
                  found struct `RangeFull`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:42:16
+  --> $DIR/issue-54505-no-std.rs:44:16
    |
 LL |     take_range(0..=1);
    |     ---------- ^^^^^
@@ -67,13 +77,13 @@ LL |     take_range(0..=1);
    = note: expected reference `&_`
                  found struct `RangeInclusive<{integer}>`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:47:16
+  --> $DIR/issue-54505-no-std.rs:49:16
    |
 LL |     take_range(..5);
    |     ---------- ^^^
@@ -85,13 +95,13 @@ LL |     take_range(..5);
    = note: expected reference `&_`
                  found struct `RangeTo<{integer}>`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
 error[E0308]: mismatched types
-  --> $DIR/issue-54505-no-std.rs:52:16
+  --> $DIR/issue-54505-no-std.rs:54:16
    |
 LL |     take_range(..=42);
    |     ---------- ^^^^^
@@ -103,11 +113,11 @@ LL |     take_range(..=42);
    = note: expected reference `&_`
                  found struct `RangeToInclusive<{integer}>`
 note: function defined here
-  --> $DIR/issue-54505-no-std.rs:23:4
+  --> $DIR/issue-54505-no-std.rs:25:4
    |
 LL | fn take_range(_r: &impl RangeBounds<i8>) {}
    |    ^^^^^^^^^^ -------------------------
 
-error: aborting due to 7 previous errors
+error: aborting due to 8 previous errors
 
 For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/target-feature/invalid-attribute.stderr b/src/test/ui/target-feature/invalid-attribute.stderr
index 889ced9752b..a2adfc67f08 100644
--- a/src/test/ui/target-feature/invalid-attribute.stderr
+++ b/src/test/ui/target-feature/invalid-attribute.stderr
@@ -4,36 +4,6 @@ error: malformed `target_feature` attribute input
 LL | #[target_feature = "+sse2"]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[target_feature(enable = "name")]`
 
-error: the feature named `foo` is not valid for this target
-  --> $DIR/invalid-attribute.rs:19:18
-   |
-LL | #[target_feature(enable = "foo")]
-   |                  ^^^^^^^^^^^^^^ `foo` is not valid for this target
-
-error: malformed `target_feature` attribute input
-  --> $DIR/invalid-attribute.rs:22:18
-   |
-LL | #[target_feature(bar)]
-   |                  ^^^ help: must be of the form: `enable = ".."`
-
-error: malformed `target_feature` attribute input
-  --> $DIR/invalid-attribute.rs:24:18
-   |
-LL | #[target_feature(disable = "baz")]
-   |                  ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
-
-error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
-  --> $DIR/invalid-attribute.rs:28:1
-   |
-LL | #[target_feature(enable = "sse2")]
-   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-...
-LL | fn bar() {}
-   | -------- not an `unsafe` function
-   |
-   = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
-   = help: add `#![feature(target_feature_11)]` to the crate attributes to enable
-
 error: attribute should be applied to a function definition
   --> $DIR/invalid-attribute.rs:34:1
    |
@@ -92,12 +62,6 @@ LL |
 LL | trait Baz {}
    | ------------ not a function definition
 
-error: cannot use `#[inline(always)]` with `#[target_feature]`
-  --> $DIR/invalid-attribute.rs:67:1
-   |
-LL | #[inline(always)]
-   | ^^^^^^^^^^^^^^^^^
-
 error: attribute should be applied to a function definition
   --> $DIR/invalid-attribute.rs:85:5
    |
@@ -119,6 +83,42 @@ LL |
 LL |     || {};
    |     ----- not a function definition
 
+error: the feature named `foo` is not valid for this target
+  --> $DIR/invalid-attribute.rs:19:18
+   |
+LL | #[target_feature(enable = "foo")]
+   |                  ^^^^^^^^^^^^^^ `foo` is not valid for this target
+
+error: malformed `target_feature` attribute input
+  --> $DIR/invalid-attribute.rs:22:18
+   |
+LL | #[target_feature(bar)]
+   |                  ^^^ help: must be of the form: `enable = ".."`
+
+error: malformed `target_feature` attribute input
+  --> $DIR/invalid-attribute.rs:24:18
+   |
+LL | #[target_feature(disable = "baz")]
+   |                  ^^^^^^^^^^^^^^^ help: must be of the form: `enable = ".."`
+
+error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
+  --> $DIR/invalid-attribute.rs:28:1
+   |
+LL | #[target_feature(enable = "sse2")]
+   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+...
+LL | fn bar() {}
+   | -------- not an `unsafe` function
+   |
+   = note: see issue #69098 <https://github.com/rust-lang/rust/issues/69098> for more information
+   = help: add `#![feature(target_feature_11)]` to the crate attributes to enable
+
+error: cannot use `#[inline(always)]` with `#[target_feature]`
+  --> $DIR/invalid-attribute.rs:67:1
+   |
+LL | #[inline(always)]
+   | ^^^^^^^^^^^^^^^^^
+
 error[E0658]: `#[target_feature(..)]` can only be applied to `unsafe` functions
   --> $DIR/invalid-attribute.rs:77:5
    |
diff --git a/src/test/ui/traits/issue-102989.rs b/src/test/ui/traits/issue-102989.rs
index 62f95272fbf..216cd78e56f 100644
--- a/src/test/ui/traits/issue-102989.rs
+++ b/src/test/ui/traits/issue-102989.rs
@@ -7,10 +7,8 @@ trait Sized { } //~ ERROR found duplicate lang item `sized`
 fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
     //~^ ERROR `self` parameter is only allowed in associated functions
     //~| ERROR cannot find type `Struct` in this scope
-    //~| ERROR mismatched types
     let x = x << 1;
-    //~^ ERROR the size for values of type `{integer}` cannot be known at compilation time
-    //~| ERROR cannot find value `x` in this scope
+    //~^ ERROR cannot find value `x` in this scope
 }
 
 fn main() {}
diff --git a/src/test/ui/traits/issue-102989.stderr b/src/test/ui/traits/issue-102989.stderr
index efe1a246774..7d0098fe885 100644
--- a/src/test/ui/traits/issue-102989.stderr
+++ b/src/test/ui/traits/issue-102989.stderr
@@ -13,7 +13,7 @@ LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
    |                      ^^^^^^ not found in this scope
 
 error[E0425]: cannot find value `x` in this scope
-  --> $DIR/issue-102989.rs:11:13
+  --> $DIR/issue-102989.rs:10:13
    |
 LL |     let x = x << 1;
    |             ^ help: a local variable with a similar name exists: `f`
@@ -28,32 +28,7 @@ LL | trait Sized { }
    = note: first definition in `core` loaded from SYSROOT/libcore-*.rlib
    = note: second definition in the local crate (`issue_102989`)
 
-error[E0277]: the size for values of type `{integer}` cannot be known at compilation time
-  --> $DIR/issue-102989.rs:11:15
-   |
-LL |     let x = x << 1;
-   |               ^^ doesn't have a size known at compile-time
-   |
-   = help: the trait `std::marker::Sized` is not implemented for `{integer}`
-
-error[E0308]: mismatched types
-  --> $DIR/issue-102989.rs:7:42
-   |
-LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
-   |    ----------                            ^^^^ expected `&u32`, found `()`
-   |    |
-   |    implicitly returns `()` as its body has no tail or `return` expression
-   |
-note: consider returning one of these bindings
-  --> $DIR/issue-102989.rs:7:30
-   |
-LL | fn ref_Struct(self: &Struct, f: &u32) -> &u32 {
-   |                              ^
-...
-LL |     let x = x << 1;
-   |         ^
-
-error: aborting due to 6 previous errors
+error: aborting due to 4 previous errors
 
-Some errors have detailed explanations: E0152, E0277, E0308, E0412, E0425.
+Some errors have detailed explanations: E0152, E0412, E0425.
 For more information about an error, try `rustc --explain E0152`.