]> git.lizzy.rs Git - rust.git/commitdiff
Ensure codegen_fn_attrs during collection.
authorCamille GILLOT <gillot.camille@gmail.com>
Sun, 6 Nov 2022 16:28:07 +0000 (16:28 +0000)
committerCamille GILLOT <gillot.camille@gmail.com>
Sun, 13 Nov 2022 14:02:15 +0000 (14:02 +0000)
12 files changed:
compiler/rustc_hir_analysis/src/collect.rs
compiler/rustc_passes/src/check_attr.rs
src/test/ui/lang-items/lang-item-generic-requirements.rs
src/test/ui/lang-items/lang-item-generic-requirements.stderr
src/test/ui/macros/issue-68060.rs
src/test/ui/macros/issue-68060.stderr
src/test/ui/panic-handler/panic-handler-std.stderr
src/test/ui/range/issue-54505-no-std.rs
src/test/ui/range/issue-54505-no-std.stderr
src/test/ui/target-feature/invalid-attribute.stderr
src/test/ui/traits/issue-102989.rs
src/test/ui/traits/issue-102989.stderr

index 0e7a5ebf5ab6245e205951a36c1d8765212f3ec3..0f8d4e9654abbebb108c57fbbdb9c6055d13d895 100644 (file)
@@ -314,6 +314,7 @@ fn visit_expr(&mut self, expr: &'tcx hir::Expr<'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(_) => {
index 2b6ff0a5cb9d38ce25a35bbbd871e27dc904cbfc..f3fc26e4784bdc3758b8910faccb0310e7822282 100644 (file)
@@ -219,18 +219,6 @@ fn check_attributes(
             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);
     }
index fbb56e528c0a62a43d8a4cda532e336dd1458b42..3d33adf68316b112315acfa0d7696f2707160fd3 100644 (file)
@@ -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
index 326f5b0d59507317f8c06d3b7076a900c5492e57..4d349a25f9c2a94d61baf1a814a5c658454ebe3b 100644 (file)
@@ -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`.
index aa8f578adf61eff295986e53944eaf5d491f5e76..fb40cd5387b7cc74dcb5add70314e0ed67689613 100644 (file)
@@ -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
         )
index b13e418e664a6a7fd3e598214e67a4906227e3d0..52e6ed92e9d238dbddd19a07f6155e5afc34b0e6 100644 (file)
@@ -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`.
index e4069b196ff04a31e3709d85b947fd0bda8f1141..7c7feffe76a13456feea33a3d20d2250cddebf81 100644 (file)
@@ -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`.
index ab1a025b521a95e93606bb0ce56613c9b322b684..9f378b4836e481bffed0cd8c575d3df3a491b08c 100644 (file)
@@ -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>) {}
index c4e36b0b159507a862352fe620ade1ca136419f8..9fb0e54a8a9bfef119f7436a480fd58205e81158 100644 (file)
@@ -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`.
index 889ced9752bd4520b3460ac8cc78ec679a28c157..a2adfc67f08001322711a338f9cdbb292cc94beb 100644 (file)
@@ -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
    |
index 62f95272fbfd26637104a676bead5a2ff712bca0..216cd78e56f9a2f1980267379edc4af9088a268e 100644 (file)
@@ -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() {}
index efe1a246774576a450cc5c0b25c610f89080c481..7d0098fe885021b22962887b2e7dcdba3a34d664 100644 (file)
@@ -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`.