Skip to content

Commit 764746e

Browse files
wip
1 parent efb4eb7 commit 764746e

File tree

72 files changed

+995
-1393
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+995
-1393
lines changed

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
826826
hir_id,
827827
&i.attrs,
828828
i.span,
829-
Target::from_assoc_item_kind(&i.kind, false),
829+
Target::from_assoc_item_kind(&i.kind, AssocCtxt::Trait),
830830
);
831831
let trait_item_def_id = hir_id.expect_owner();
832832

@@ -1002,7 +1002,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
10021002
hir_id,
10031003
&i.attrs,
10041004
i.span,
1005-
Target::from_assoc_item_kind(&i.kind, is_in_trait_impl),
1005+
Target::from_assoc_item_kind(&i.kind, AssocCtxt::Impl { of_trait: is_in_trait_impl }),
10061006
);
10071007

10081008
let (ident, (generics, kind)) = match &i.kind {

compiler/rustc_attr_parsing/src/attributes/codegen_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,7 @@ impl<S: Stage> CombineAttributeParser<S> for TargetFeatureParser {
435435
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
436436
Allow(Target::Fn),
437437
Allow(Target::Method(MethodKind::Inherent)),
438+
Allow(Target::Method(MethodKind::Trait {body: true})),
438439
Warn(Target::Statement),
439440
Warn(Target::Field),
440441
Warn(Target::Arm),

compiler/rustc_attr_parsing/src/attributes/deprecation.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_span::{Span, Symbol, sym};
55

66
use super::util::parse_version;
77
use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
8-
use crate::context::MaybeWarn::{Allow, Warn};
8+
use crate::context::MaybeWarn::{Allow};
99
use crate::context::{AcceptContext, AllowedTargets, Stage};
1010
use crate::parser::ArgParser;
1111
use crate::session_diagnostics;
@@ -39,7 +39,7 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
3939
const PATH: &[Symbol] = &[sym::deprecated];
4040
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
4141
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
42-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
42+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowListWarnRest(&[
4343
Allow(Target::Fn),
4444
Allow(Target::Mod),
4545
Allow(Target::Struct),
@@ -58,15 +58,6 @@ impl<S: Stage> SingleAttributeParser<S> for DeprecationParser {
5858
Allow(Target::AssocTy),
5959
Allow(Target::AssocConst),
6060
Allow(Target::Variant),
61-
Warn(Target::Expression),
62-
Warn(Target::Impl { of_trait: false }),
63-
Warn(Target::Impl { of_trait: true }),
64-
Warn(Target::Crate),
65-
Warn(Target::Param),
66-
Warn(Target::Closure),
67-
Warn(Target::Expression),
68-
Warn(Target::Statement),
69-
Warn(Target::Arm),
7061
]);
7162
const TEMPLATE: AttributeTemplate = template!(
7263
Word,

compiler/rustc_attr_parsing/src/attributes/lint_helpers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) struct PassByValueParser;
3434
impl<S: Stage> NoArgsAttributeParser<S> for PassByValueParser {
3535
const PATH: &[Symbol] = &[sym::rustc_pass_by_value];
3636
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
37-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct)]);
37+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Struct), Allow(Target::Enum), Allow(Target::TyAlias)]);
3838
const CREATE: fn(Span) -> AttributeKind = AttributeKind::PassByValue;
3939
}
4040

compiler/rustc_attr_parsing/src/attributes/traits.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,6 @@ pub(crate) struct PointeeParser;
172172
impl<S: Stage> NoArgsAttributeParser<S> for PointeeParser {
173173
const PATH: &[Symbol] = &[sym::pointee];
174174
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
175-
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Param)]);
175+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowAll; //TODO
176176
const CREATE: fn(Span) -> AttributeKind = AttributeKind::Pointee;
177177
}

compiler/rustc_builtin_macros/messages.ftl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ builtin_macros_only_one_argument = {$name} takes 1 argument
259259
260260
builtin_macros_proc_macro = `proc-macro` crate types currently cannot export any items other than functions tagged with `#[proc_macro]`, `#[proc_macro_derive]`, or `#[proc_macro_attribute]`
261261
262-
builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions = the `#[{$path}]` attribute may only be used on bare functions
263-
264262
builtin_macros_proc_macro_attribute_only_usable_with_crate_type = the `#[{$path}]` attribute is only usable with crates of the `proc-macro` crate type
265263
266264
builtin_macros_requires_cfg_pattern =

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -905,14 +905,6 @@ pub(crate) struct TakesNoArguments<'a> {
905905
pub name: &'a str,
906906
}
907907

908-
#[derive(Diagnostic)]
909-
#[diag(builtin_macros_proc_macro_attribute_only_be_used_on_bare_functions)]
910-
pub(crate) struct AttributeOnlyBeUsedOnBareFunctions<'a> {
911-
#[primary_span]
912-
pub span: Span,
913-
pub path: &'a str,
914-
}
915-
916908
#[derive(Diagnostic)]
917909
#[diag(builtin_macros_proc_macro_attribute_only_usable_with_crate_type)]
918910
pub(crate) struct AttributeOnlyUsableWithCrateType<'a> {

compiler/rustc_builtin_macros/src/proc_macro_harness.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -232,12 +232,7 @@ impl<'a> Visitor<'a> for CollectProcMacros<'a> {
232232
let fn_ident = if let ast::ItemKind::Fn(fn_) = &item.kind {
233233
fn_.ident
234234
} else {
235-
self.dcx
236-
.create_err(errors::AttributeOnlyBeUsedOnBareFunctions {
237-
span: attr.span,
238-
path: &pprust::path_to_string(&attr.get_normal_item().path),
239-
})
240-
.emit();
235+
// Error handled by general target checking logic
241236
return;
242237
};
243238

compiler/rustc_error_codes/src/error_codes/E0518.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
13
An `#[inline(..)]` attribute was incorrectly placed on something other than a
24
function or method.
35

46
Example of erroneous code:
57

6-
```compile_fail,E0518
8+
```ignore (no longer emitted)
79
#[inline(always)]
810
struct Foo;
911

compiler/rustc_hir/src/target.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
use std::fmt::{self, Display};
88

99
use rustc_ast::{AssocItemKind, ForeignItemKind, ast};
10-
10+
use rustc_ast::visit::AssocCtxt;
1111
use crate::def::DefKind;
1212
use crate::{Item, ItemKind, TraitItem, TraitItemKind, hir};
1313

@@ -226,13 +226,16 @@ impl Target {
226226
}
227227
}
228228

229-
pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, is_in_trait_impl: bool) -> Target {
229+
pub fn from_assoc_item_kind(kind: &ast::AssocItemKind, assoc_ctxt: AssocCtxt) -> Target {
230230
match kind {
231231
AssocItemKind::Const(_) => Target::AssocConst,
232-
AssocItemKind::Fn(_) => Target::Method(if is_in_trait_impl {
233-
MethodKind::Trait { body: true }
234-
} else {
235-
MethodKind::Inherent
232+
AssocItemKind::Fn(f) => Target::Method(match assoc_ctxt {
233+
AssocCtxt::Trait => MethodKind::Trait { body: f.body.is_some() },
234+
AssocCtxt::Impl { of_trait } => if of_trait {
235+
MethodKind::Trait { body: true }
236+
} else {
237+
MethodKind::Inherent
238+
}
236239
}),
237240
AssocItemKind::Type(_) => Target::AssocTy,
238241
AssocItemKind::Delegation(_) => Target::Delegation,

0 commit comments

Comments
 (0)