Skip to content

Commit d6ae9a1

Browse files
authored
Unrolled build for #150829
Rollup merge of #150829 - fix_generic_param_target, r=JonathanBrouwer make attrs actually use `Target::GenericParam` currently attributes lower `GenericParam` -> `Target::Param` this PR fixes this, so that `GenericParam` is lowered to `Target::GenericParam` r? @JonathanBrouwer
2 parents 85d0cdf + 742d276 commit d6ae9a1

11 files changed

Lines changed: 47 additions & 19 deletions

File tree

compiler/rustc_ast_lowering/src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,8 +1986,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19861986
let (name, kind) = self.lower_generic_param_kind(param, source);
19871987

19881988
let hir_id = self.lower_node_id(param.id);
1989-
self.lower_attrs(hir_id, &param.attrs, param.span(), Target::Param);
1990-
hir::GenericParam {
1989+
let param_attrs = &param.attrs;
1990+
let param_span = param.span();
1991+
let param = hir::GenericParam {
19911992
hir_id,
19921993
def_id: self.local_def_id(param.id),
19931994
name,
@@ -1996,7 +1997,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
19961997
kind,
19971998
colon_span: param.colon_span.map(|s| self.lower_span(s)),
19981999
source,
1999-
}
2000+
};
2001+
self.lower_attrs(hir_id, param_attrs, param_span, Target::from_generic_param(&param));
2002+
param
20002003
}
20012004

20022005
fn lower_generic_param_kind(

compiler/rustc_attr_parsing/src/attributes/stability.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::num::NonZero;
22

33
use rustc_errors::ErrorGuaranteed;
4+
use rustc_hir::target::GenericParamKind;
45
use rustc_hir::{
56
DefaultBodyStability, MethodKind, PartialConstStability, Stability, StabilityLevel,
67
StableSince, Target, UnstableReason, VERSION_PLACEHOLDER,
@@ -43,7 +44,7 @@ const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
4344
Allow(Target::TyAlias),
4445
Allow(Target::Variant),
4546
Allow(Target::Field),
46-
Allow(Target::Param),
47+
Allow(Target::GenericParam { kind: GenericParamKind::Type, has_default: true }),
4748
Allow(Target::Static),
4849
Allow(Target::ForeignFn),
4950
Allow(Target::ForeignStatic),

compiler/rustc_attr_parsing/src/target_checking.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,5 +310,29 @@ pub(crate) const ALL_TARGETS: &'static [Policy] = {
310310
Allow(Target::Crate),
311311
Allow(Target::Delegation { mac: false }),
312312
Allow(Target::Delegation { mac: true }),
313+
Allow(Target::GenericParam {
314+
kind: rustc_hir::target::GenericParamKind::Const,
315+
has_default: false,
316+
}),
317+
Allow(Target::GenericParam {
318+
kind: rustc_hir::target::GenericParamKind::Const,
319+
has_default: true,
320+
}),
321+
Allow(Target::GenericParam {
322+
kind: rustc_hir::target::GenericParamKind::Lifetime,
323+
has_default: false,
324+
}),
325+
Allow(Target::GenericParam {
326+
kind: rustc_hir::target::GenericParamKind::Lifetime,
327+
has_default: true,
328+
}),
329+
Allow(Target::GenericParam {
330+
kind: rustc_hir::target::GenericParamKind::Type,
331+
has_default: false,
332+
}),
333+
Allow(Target::GenericParam {
334+
kind: rustc_hir::target::GenericParamKind::Type,
335+
has_default: true,
336+
}),
313337
]
314338
};

compiler/rustc_hir/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub mod lints;
3232
pub mod pat_util;
3333
mod stability;
3434
mod stable_hash_impls;
35-
mod target;
35+
pub mod target;
3636
pub mod weak_lang_items;
3737

3838
#[cfg(test)]

tests/ui/const-generics/invalid-attributes-on-const-params-78957.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
1-
error: `#[inline]` attribute cannot be used on function params
1+
error: `#[inline]` attribute cannot be used on const parameters
22
--> $DIR/invalid-attributes-on-const-params-78957.rs:6:16
33
|
44
LL | pub struct Foo<#[inline] const N: usize>;
55
| ^^^^^^^^^
66
|
77
= help: `#[inline]` can only be applied to functions
88

9-
error: `#[inline]` attribute cannot be used on function params
9+
error: `#[inline]` attribute cannot be used on lifetime parameters
1010
--> $DIR/invalid-attributes-on-const-params-78957.rs:14:17
1111
|
1212
LL | pub struct Foo2<#[inline] 'a>(PhantomData<&'a ()>);
1313
| ^^^^^^^^^
1414
|
1515
= help: `#[inline]` can only be applied to functions
1616

17-
error: `#[inline]` attribute cannot be used on function params
17+
error: `#[inline]` attribute cannot be used on type parameters
1818
--> $DIR/invalid-attributes-on-const-params-78957.rs:22:17
1919
|
2020
LL | pub struct Foo3<#[inline] T>(PhantomData<T>);
@@ -40,7 +40,7 @@ error[E0517]: attribute should be applied to a struct, enum, or union
4040
LL | pub struct Baz3<#[repr(C)] T>(PhantomData<T>);
4141
| ^ - not a struct, enum, or union
4242

43-
error: `#[cold]` attribute cannot be used on function params
43+
error: `#[cold]` attribute cannot be used on const parameters
4444
--> $DIR/invalid-attributes-on-const-params-78957.rs:8:16
4545
|
4646
LL | pub struct Bar<#[cold] const N: usize>;
@@ -54,7 +54,7 @@ note: the lint level is defined here
5454
LL | #![deny(unused_attributes)]
5555
| ^^^^^^^^^^^^^^^^^
5656

57-
error: `#[cold]` attribute cannot be used on function params
57+
error: `#[cold]` attribute cannot be used on lifetime parameters
5858
--> $DIR/invalid-attributes-on-const-params-78957.rs:16:17
5959
|
6060
LL | pub struct Bar2<#[cold] 'a>(PhantomData<&'a ()>);
@@ -63,7 +63,7 @@ LL | pub struct Bar2<#[cold] 'a>(PhantomData<&'a ()>);
6363
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6464
= help: `#[cold]` can only be applied to functions
6565

66-
error: `#[cold]` attribute cannot be used on function params
66+
error: `#[cold]` attribute cannot be used on type parameters
6767
--> $DIR/invalid-attributes-on-const-params-78957.rs:24:17
6868
|
6969
LL | pub struct Bar3<#[cold] T>(PhantomData<T>);

tests/ui/force-inlining/invalid.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ LL | #[rustc_force_inline]
152152
|
153153
= help: `#[rustc_force_inline]` can only be applied to functions
154154

155-
error: `#[rustc_force_inline]` attribute cannot be used on function params
155+
error: `#[rustc_force_inline]` attribute cannot be used on type parameters
156156
--> $DIR/invalid.rs:72:10
157157
|
158158
LL | enum Bar<#[rustc_force_inline] T> {

tests/ui/lint/unused/unused_attributes-must_use.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ LL | #[must_use]
9393
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9494
= help: `#[must_use]` can be applied to data types, functions, traits, and unions
9595

96-
error: `#[must_use]` attribute cannot be used on function params
96+
error: `#[must_use]` attribute cannot be used on type parameters
9797
--> $DIR/unused_attributes-must_use.rs:77:8
9898
|
9999
LL | fn qux<#[must_use] T>(_: T) {}

tests/ui/pin-ergonomics/pin_v2-attr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ union Union {
2525
// disallowed
2626

2727
enum Foo<#[pin_v2] T, #[pin_v2] U = ()> {
28-
//~^ ERROR `#[pin_v2]` attribute cannot be used on function params
29-
//~| ERROR `#[pin_v2]` attribute cannot be used on function params
28+
//~^ ERROR `#[pin_v2]` attribute cannot be used on type parameters
29+
//~| ERROR `#[pin_v2]` attribute cannot be used on type parameters
3030
#[pin_v2] //~ ERROR `#[pin_v2]` attribute cannot be used on enum variants
3131
UnitVariant,
3232
TupleVariant(#[pin_v2] T), //~ ERROR `#[pin_v2]` attribute cannot be used on struct fields

tests/ui/pin-ergonomics/pin_v2-attr.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ LL | #![pin_v2]
2020
|
2121
= help: `#[pin_v2]` can be applied to data types and unions
2222

23-
error: `#[pin_v2]` attribute cannot be used on function params
23+
error: `#[pin_v2]` attribute cannot be used on type parameters
2424
--> $DIR/pin_v2-attr.rs:27:10
2525
|
2626
LL | enum Foo<#[pin_v2] T, #[pin_v2] U = ()> {
2727
| ^^^^^^^^^
2828
|
2929
= help: `#[pin_v2]` can be applied to data types and unions
3030

31-
error: `#[pin_v2]` attribute cannot be used on function params
31+
error: `#[pin_v2]` attribute cannot be used on type parameters
3232
--> $DIR/pin_v2-attr.rs:27:23
3333
|
3434
LL | enum Foo<#[pin_v2] T, #[pin_v2] U = ()> {

tests/ui/scalable-vectors/invalid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ type Foo = u32;
4848
#[rustc_scalable_vector(4)]
4949
//~^ ERROR: `#[rustc_scalable_vector]` attribute cannot be used on enums
5050
enum Bar<#[rustc_scalable_vector(4)] T> {
51-
//~^ ERROR: `#[rustc_scalable_vector]` attribute cannot be used on function params
51+
//~^ ERROR: `#[rustc_scalable_vector]` attribute cannot be used on type parameters
5252
#[rustc_scalable_vector(4)]
5353
//~^ ERROR: `#[rustc_scalable_vector]` attribute cannot be used on enum variants
5454
Baz(std::marker::PhantomData<T>),

0 commit comments

Comments
 (0)