Skip to content

Commit

Permalink
Fix all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Jan 20, 2025
1 parent 4d38c0b commit 7319c1a
Show file tree
Hide file tree
Showing 63 changed files with 552 additions and 673 deletions.
71 changes: 5 additions & 66 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ pub enum ReprAttr {
ReprSimd,
ReprTransparent,
ReprAlign(Align),
// this one is just so we can emit a lint for it
ReprEmpty,
}
pub use ReprAttr::*;

Expand Down Expand Up @@ -139,26 +141,16 @@ impl Deprecation {
/// happen.
///
/// For more docs, look in [`rustc_attr`](https://doc.rust-lang.org/stable/nightly-rustc/rustc_attr/index.html)
// FIXME(jdonszelmann): rename to AttributeKind once hir::AttributeKind is dissolved
#[derive(Clone, Debug, HashStable_Generic, Encodable, Decodable)]
pub enum AttributeKind {
// tidy-alphabetical-start
Allow,
AllowConstFnUnstable(ThinVec<Symbol>),
AllowInternalUnsafe,
AllowInternalUnstable(ThinVec<Symbol>),
AutoDiff,
AutomaticallyDerived,
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
BodyStability {
stability: DefaultBodyStability,
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
span: Span,
},
Cfg,
CfgAttr,
CfiEncoding, // FIXME(cfi_encoding)
Cold,
CollapseDebuginfo,
Confusables {
symbols: ThinVec<Symbol>,
// FIXME(jdonszelmann): remove when target validation code is moved
Expand All @@ -170,14 +162,6 @@ pub enum AttributeKind {
span: Span,
},
ConstStabilityIndirect,
ConstTrait,
Coroutine,
Coverage,
CustomMir,
DebuggerVisualizer,
DefaultLibAllocator,
Deny,
DeprecatedSafe, // FIXME(deprecated_safe)
Deprecation {
deprecation: Deprecation,
span: Span,
Expand All @@ -193,57 +177,12 @@ pub enum AttributeKind {
span: Span,
comment: Symbol,
},
Expect,
ExportName,
FfiConst,
FfiPure,
Forbid,
Fundamental,
Ignore,
// TODO: must contain span for clippy
Inline,
InstructionSet, // broken on stable!!!
Lang,
Link,
Linkage,
LinkName,
LinkOrdinal,
LinkSection,
MacroExport,
MacroTransparency(Transparency),
MacroUse,
Marker,
MayDangle,
MustNotSuspend,
MustUse,
NeedsAllocator,
NoImplicitPrelude,
NoLink,
NoMangle,
NonExhaustive,
NoSanitize,
OmitGdbPrettyPrinterSection, // FIXME(omit_gdb_pretty_printer_section)
PanicHandler,
PatchableFunctionEntry, // FIXME(patchable_function_entry)
Path,
Pointee, // FIXME(derive_smart_pointer)
PreludeImport,
ProcMacro,
ProcMacroAttribute,
ProcMacroDerive,
Repr(ThinVec<ReprAttr>),
Repr(ThinVec<(ReprAttr, Span)>),
Stability {
stability: Stability,
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute
span: Span,
},
Start,
TargetFeature,
ThreadLocal,
TrackCaller,
Unstable,
Used,
Warn,
WindowsSubsystem, // broken on stable!!!
// tidy-alphabetical-end
// tidy-alphabetical-end
}
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ attr_parsing_non_ident_feature =
attr_parsing_repr_ident =
meta item in `repr` must be an identifier
attr_parsing_rustc_allowed_unstable_pairing =
`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
Expand Down
12 changes: 7 additions & 5 deletions compiler/rustc_attr_parsing/src/attributes/allow_unstable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::iter;

use rustc_attr_data_structures::AttributeKind;
use rustc_span::{Symbol, sym};
use rustc_span::{Span, Symbol, sym};

use super::{CombineAttributeParser, ConvertFn};
use crate::context::AcceptContext;
Expand All @@ -9,14 +11,14 @@ use crate::session_diagnostics;
pub(crate) struct AllowInternalUnstableParser;
impl CombineAttributeParser for AllowInternalUnstableParser {
const PATH: &'static [rustc_span::Symbol] = &[sym::allow_internal_unstable];
type Item = Symbol;
type Item = (Symbol, Span);
const CONVERT: ConvertFn<Self::Item> = AttributeKind::AllowInternalUnstable;

fn extend<'a>(
cx: &'a AcceptContext<'a>,
args: &'a ArgParser<'a>,
) -> impl IntoIterator<Item = Self::Item> + 'a {
parse_unstable(cx, args, Self::PATH[0])
parse_unstable(cx, args, Self::PATH[0]).into_iter().zip(iter::repeat(cx.attr_span))
}
}

Expand All @@ -42,7 +44,7 @@ fn parse_unstable<'a>(
let mut res = Vec::new();

let Some(list) = args.list() else {
cx.dcx().emit_err(session_diagnostics::ExpectsFeatureList {
cx.emit_err(session_diagnostics::ExpectsFeatureList {
span: cx.attr_span,
name: symbol.to_ident_string(),
});
Expand All @@ -54,7 +56,7 @@ fn parse_unstable<'a>(
if let Some(ident) = param.meta_item().and_then(|i| i.word_without_args()) {
res.push(ident.name);
} else {
cx.dcx().emit_err(session_diagnostics::ExpectsFeatures {
cx.emit_err(session_diagnostics::ExpectsFeatures {
span: param_span,
name: symbol.to_ident_string(),
});
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/cfg.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: convert cfg properly.... And learn how cfg works I guess
use rustc_ast::{LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NodeId};
use rustc_ast_pretty::pprust;
use rustc_attr_data_structures::RustcVersion;
Expand Down
9 changes: 4 additions & 5 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ use rustc_attr_data_structures::AttributeKind;
use rustc_span::{Span, Symbol, sym};
use thin_vec::ThinVec;

use crate::session_diagnostics;

use super::{AcceptMapping, AttributeParser, FinalizeContext};
use crate::session_diagnostics;

#[derive(Default)]
pub(crate) struct ConfusablesParser {
Expand All @@ -15,21 +14,21 @@ pub(crate) struct ConfusablesParser {
impl AttributeParser for ConfusablesParser {
const ATTRIBUTES: AcceptMapping<Self> = &[(&[sym::rustc_confusables], |this, cx, args| {
let Some(list) = args.list() else {
// TODO: error when not a list? Bring validation code here.
// FIXME(jdonszelmann): error when not a list? Bring validation code here.
// NOTE: currently subsequent attributes are silently ignored using
// tcx.get_attr().
return;
};

if list.is_empty() {
cx.dcx().emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
cx.emit_err(session_diagnostics::EmptyConfusables { span: cx.attr_span });
}

for param in list.mixed() {
let span = param.span();

let Some(lit) = param.lit() else {
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
cx.emit_err(session_diagnostics::IncorrectMetaItem {
span,
suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion {
lo: span.shrink_to_lo(),
Expand Down
23 changes: 10 additions & 13 deletions compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fn get(
item: &mut Option<Symbol>,
) -> bool {
if item.is_some() {
cx.dcx().emit_err(session_diagnostics::MultipleItem {
cx.emit_err(session_diagnostics::MultipleItem {
span: param_span,
item: ident.to_string(),
});
Expand All @@ -31,7 +31,7 @@ fn get(
true
} else {
let lit = v.value_as_lit();
cx.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
cx.emit_err(session_diagnostics::UnsupportedLiteral {
span: v.value_span,
reason: UnsupportedLiteralReason::DeprecatedString,
is_bytestr: lit.kind.is_bytestr(),
Expand All @@ -41,10 +41,7 @@ fn get(
}
} else {
// FIXME(jdonszelmann): suggestion?
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
span: param_span,
suggestion: None,
});
cx.emit_err(session_diagnostics::IncorrectMetaItem { span: param_span, suggestion: None });
false
}
}
Expand All @@ -54,7 +51,7 @@ impl SingleAttributeParser for DeprecationParser {

fn on_duplicate(cx: &AcceptContext<'_>, first_span: rustc_span::Span) {
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
cx.dcx().emit_err(session_diagnostics::UnusedMultiple {
cx.emit_err(session_diagnostics::UnusedMultiple {
this: cx.attr_span,
other: first_span,
name: sym::deprecated,
Expand All @@ -78,7 +75,7 @@ impl SingleAttributeParser for DeprecationParser {
for param in list.mixed() {
let param_span = param.span();
let Some(param) = param.meta_item() else {
cx.dcx().emit_err(session_diagnostics::UnsupportedLiteral {
cx.emit_err(session_diagnostics::UnsupportedLiteral {
span: param_span,
reason: UnsupportedLiteralReason::DeprecatedKvPair,
is_bytestr: false,
Expand All @@ -102,7 +99,7 @@ impl SingleAttributeParser for DeprecationParser {
}
sym::suggestion => {
if !features.deprecated_suggestion() {
cx.dcx().emit_err(session_diagnostics::DeprecatedItemSuggestion {
cx.emit_err(session_diagnostics::DeprecatedItemSuggestion {
span: param_span,
is_nightly: cx.sess().is_nightly_build(),
details: (),
Expand All @@ -114,7 +111,7 @@ impl SingleAttributeParser for DeprecationParser {
}
}
_ => {
cx.dcx().emit_err(session_diagnostics::UnknownMetaItem {
cx.emit_err(session_diagnostics::UnknownMetaItem {
span: param_span,
item: ident.to_string(),
expected: if features.deprecated_suggestion() {
Expand All @@ -137,18 +134,18 @@ impl SingleAttributeParser for DeprecationParser {
} else if let Some(version) = parse_version(since) {
DeprecatedSince::RustcVersion(version)
} else {
cx.dcx().emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
cx.emit_err(session_diagnostics::InvalidSince { span: cx.attr_span });
DeprecatedSince::Err
}
} else if is_rustc {
cx.dcx().emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
cx.emit_err(session_diagnostics::MissingSince { span: cx.attr_span });
DeprecatedSince::Err
} else {
DeprecatedSince::Unspecified
};

if is_rustc && note.is_none() {
cx.dcx().emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
cx.emit_err(session_diagnostics::MissingNote { span: cx.attr_span });
return None;
}

Expand Down
Loading

0 comments on commit 7319c1a

Please sign in to comment.