Skip to content

Commit 66feb37

Browse files
wip
1 parent 5ca8a50 commit 66feb37

File tree

13 files changed

+994
-853
lines changed

13 files changed

+994
-853
lines changed
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
//! Attributes that can be found in function body.
22
3+
use rustc_hir::Target;
34
use rustc_hir::attrs::AttributeKind;
45
use rustc_span::{Symbol, sym};
56

67
use super::{NoArgsAttributeParser, OnDuplicate};
7-
use crate::context::Stage;
8+
use crate::context::MaybeWarn::Allow;
9+
use crate::context::{AllowedTargets, Stage};
810

911
pub(crate) struct CoroutineParser;
1012

1113
impl<S: Stage> NoArgsAttributeParser<S> for CoroutineParser {
1214
const PATH: &[Symbol] = &[sym::coroutine];
1315
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
16+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Closure)]);
1417
const CREATE: fn(rustc_span::Span) -> AttributeKind = |span| AttributeKind::Coroutine(span);
1518
}

compiler/rustc_attr_parsing/src/attributes/test_attrs.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ impl<S: Stage> SingleAttributeParser<S> for ShouldPanicParser {
5454
const PATH: &[Symbol] = &[sym::should_panic];
5555
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
5656
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
57+
const ALLOWED_TARGETS: AllowedTargets =
58+
AllowedTargets::AllowListWarnRest(&[Allow(Target::Fn), Error(Target::WherePredicate)]);
5759
const TEMPLATE: AttributeTemplate =
5860
template!(Word, List: r#"expected = "reason""#, NameValueStr: "reason");
5961

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,8 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
921921
match accept.allowed_targets.is_allowed(target) {
922922
AllowedResult::Allowed => {}
923923
AllowedResult::Warn => {
924-
let allowed_targets = accept.allowed_targets.allowed_targets();
924+
let allowed_targets =
925+
accept.allowed_targets.allowed_targets();
925926
emit_lint(AttributeLint {
926927
id: target_id,
927928
span: attr.span,
@@ -941,13 +942,21 @@ impl<'sess, S: Stage> AttributeParser<'sess, S> {
941942
});
942943
}
943944
AllowedResult::Error => {
944-
let allowed_targets = accept.allowed_targets.allowed_targets();
945+
let allowed_targets =
946+
accept.allowed_targets.allowed_targets();
945947
self.dcx().emit_err(InvalidTarget {
946948
span: attr.span,
947949
name: parts[0],
948950
target: target.plural_name(),
949-
only: if allowed_targets.len() == 1 { "only " } else { "" },
950-
applied: allowed_targets_applied(allowed_targets, target),
951+
only: if allowed_targets.len() == 1 {
952+
"only "
953+
} else {
954+
""
955+
},
956+
applied: allowed_targets_applied(
957+
allowed_targets,
958+
target,
959+
),
951960
});
952961
}
953962
}

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ passes_const_stable_not_stable =
7070
attribute `#[rustc_const_stable]` can only be applied to functions that are declared `#[stable]`
7171
.label = attribute specified here
7272
73-
passes_coroutine_on_non_closure =
74-
attribute should be applied to closures
75-
.label = not a closure
76-
7773
passes_dead_codes =
7874
{ $multiple ->
7975
*[true] multiple {$descr}s are
@@ -462,9 +458,6 @@ passes_non_exported_macro_invalid_attrs =
462458
passes_object_lifetime_err =
463459
{$repr}
464460
465-
passes_only_has_effect_on =
466-
`#[{$attr_name}]` only has an effect on {$target_name}
467-
468461
passes_outer_crate_level_attr =
469462
crate-level attribute should be an inner attribute: add an exclamation mark: `#![foo]`
470463

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use std::collections::hash_map::Entry;
1010
use std::slice;
1111

1212
use rustc_abi::{Align, ExternAbi, Size};
13-
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, ast, join_path_syms};
13+
use rustc_ast::{AttrStyle, LitKind, MetaItemInner, MetaItemKind, ast};
1414
use rustc_attr_parsing::{AttributeParser, Late};
1515
use rustc_data_structures::fx::FxHashMap;
1616
use rustc_errors::{Applicability, DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
@@ -245,8 +245,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
245245
| AttributeKind::PassByValue (..)
246246
| AttributeKind::StdInternalSymbol (..)
247247
| AttributeKind::Coverage (..)
248-
| AttributeKind::ShouldPanic
249-
| AttributeKind::Coroutine, //TODO
248+
| AttributeKind::ShouldPanic { .. }
249+
| AttributeKind::Coroutine(..),
250250
) => { /* do nothing */ }
251251

252252
Attribute::Unparsed(attr_item) => {
@@ -513,28 +513,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
513513
}
514514
}
515515

516-
/// FIXME: Remove when all attributes are ported to the new parser
517-
fn check_generic_attr_unparsed(
518-
&self,
519-
hir_id: HirId,
520-
attr: &Attribute,
521-
target: Target,
522-
allowed_target: Target,
523-
) {
524-
if target != allowed_target {
525-
let attr_name = join_path_syms(attr.path());
526-
self.tcx.emit_node_span_lint(
527-
UNUSED_ATTRIBUTES,
528-
hir_id,
529-
attr.span(),
530-
errors::OnlyHasEffectOn {
531-
attr_name,
532-
target_name: allowed_target.plural_name().to_string(),
533-
},
534-
);
535-
}
536-
}
537-
538516
/// Checks if `#[naked]` is applied to a function definition.
539517
fn check_naked(&self, hir_id: HirId, target: Target) {
540518
match target {
@@ -2002,15 +1980,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
20021980
}
20031981
}
20041982

2005-
fn check_coroutine(&self, attr_span: Span, target: Target) {
2006-
match target {
2007-
Target::Closure => return,
2008-
_ => {
2009-
self.dcx().emit_err(errors::CoroutineOnNonClosure { span: attr_span });
2010-
}
2011-
}
2012-
}
2013-
20141983
fn check_type_const(&self, hir_id: HirId, attr_span: Span, target: Target) {
20151984
let tcx = self.tcx;
20161985
if target == Target::AssocConst

compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -504,13 +504,6 @@ pub(crate) struct RustcForceInlineCoro {
504504
pub span: Span,
505505
}
506506

507-
#[derive(Diagnostic)]
508-
#[diag(passes_coroutine_on_non_closure)]
509-
pub(crate) struct CoroutineOnNonClosure {
510-
#[primary_span]
511-
pub span: Span,
512-
}
513-
514507
#[derive(Diagnostic)]
515508
#[diag(passes_linkage)]
516509
pub(crate) struct Linkage {
@@ -1022,13 +1015,6 @@ pub(crate) struct UselessAssignment<'a> {
10221015
pub ty: Ty<'a>,
10231016
}
10241017

1025-
#[derive(LintDiagnostic)]
1026-
#[diag(passes_only_has_effect_on)]
1027-
pub(crate) struct OnlyHasEffectOn {
1028-
pub attr_name: String,
1029-
pub target_name: String,
1030-
}
1031-
10321018
#[derive(LintDiagnostic)]
10331019
#[diag(passes_inline_ignored_for_exported)]
10341020
#[help]

0 commit comments

Comments
 (0)