]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #94686 - ChayimFriedman2:issue-94629, r=jackh726
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Wed, 9 Mar 2022 05:38:51 +0000 (06:38 +0100)
committerGitHub <noreply@github.com>
Wed, 9 Mar 2022 05:38:51 +0000 (06:38 +0100)
Do not allow `#[rustc_legacy_const_generics]` on methods

It caused an ICE since `item` was `None`.

Fixes #94629.

compiler/rustc_passes/src/check_attr.rs
src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.rs
src/test/ui/invalid/invalid-rustc_legacy_const_generics-arguments.stderr

index 2202001555084523b9afc39c584b15447409a7b8..01b12eec628ec074877dc828802fdd3fea137f7b 100644 (file)
@@ -1345,7 +1345,7 @@ fn check_rustc_legacy_const_generics(
         target: Target,
         item: Option<ItemLike<'_>>,
     ) -> bool {
-        let is_function = matches!(target, Target::Fn | Target::Method(..));
+        let is_function = matches!(target, Target::Fn);
         if !is_function {
             self.tcx
                 .sess
index 3d8478f06db0ea0875c640774d7a3f371955ee0b..6eabd9b1015b79602886d27770a93f7de498c1fb 100644 (file)
@@ -29,6 +29,11 @@ fn foo6<const X: usize>() {}
 #[rustc_legacy_const_generics(0)] //~ ERROR #[rustc_legacy_const_generics] functions must only have
 fn foo8<X>() {}
 
+impl S {
+    #[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function
+    fn foo9<const X: usize>() {}
+}
+
 #[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute
 fn bar1() {}
 
index 1f55a8e72d2cb29795b0c1dcc37ff071a5d4a166..bfe7bb2e10dccf7d9cd14252eb430fc64a0cc78c 100644 (file)
@@ -7,13 +7,13 @@ LL | #[rustc_legacy_const_generics(0usize)]
    = help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
 
 error: malformed `rustc_legacy_const_generics` attribute input
-  --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:32:1
+  --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:1
    |
 LL | #[rustc_legacy_const_generics]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
 
 error: malformed `rustc_legacy_const_generics` attribute input
-  --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:35:1
+  --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:40:1
    |
 LL | #[rustc_legacy_const_generics = 1]
    | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
@@ -66,6 +66,14 @@ LL | #[rustc_legacy_const_generics(0)]
 LL | fn foo8<X>() {}
    |         - non-const generic parameter
 
+error: attribute should be applied to a function
+  --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:5
+   |
+LL |     #[rustc_legacy_const_generics(0)]
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+LL |     fn foo9<const X: usize>() {}
+   |     ---------------------------- not a function
+
 error: attribute should be applied to a function
   --> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5
    |
@@ -82,6 +90,6 @@ LL |     fn foo7<const X: usize>();
    |
    = help: replace the const parameters with concrete consts
 
-error: aborting due to 12 previous errors
+error: aborting due to 13 previous errors
 
 For more information about this error, try `rustc --explain E0044`.