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 7c94afd commit 4aaff39
Show file tree
Hide file tree
Showing 64 changed files with 523 additions and 570 deletions.
8 changes: 4 additions & 4 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,13 +141,11 @@ 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
AllowConstFnUnstable(ThinVec<Symbol>),
AllowInternalUnsafe,
AllowInternalUnstable(ThinVec<Symbol>),
AllowInternalUnstable(ThinVec<(Symbol, Span)>),
BodyStability {
stability: DefaultBodyStability,
/// Span of the `#[rustc_default_body_unstable(...)]` attribute
Expand Down Expand Up @@ -174,7 +174,7 @@ pub enum AttributeKind {
comment: Symbol,
},
MacroTransparency(Transparency),
Repr(ThinVec<ReprAttr>),
Repr(ThinVec<(ReprAttr, Span)>),
Stability {
stability: Stability,
/// Span of the `#[stable(...)]` or `#[unstable(...)]` attribute
Expand Down
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
6 changes: 3 additions & 3 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,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
37 changes: 24 additions & 13 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ use crate::session_diagnostics::IncorrectReprFormatGenericCause;
pub(crate) struct ReprParser;

impl CombineAttributeParser for ReprParser {
type Item = ReprAttr;
type Item = (ReprAttr, Span);
const PATH: &'static [rustc_span::Symbol] = &[sym::repr];
const CONVERT: ConvertFn<ReprAttr> = AttributeKind::Repr;
const CONVERT: ConvertFn<Self::Item> = AttributeKind::Repr;

fn extend<'a>(
cx: &'a AcceptContext<'a>,
Expand All @@ -34,8 +34,20 @@ impl CombineAttributeParser for ReprParser {
return reprs;
};

if list.is_empty() {
// this is so validation can emit a lint
reprs.push((ReprAttr::ReprEmpty, cx.attr_span));
}

for param in list.mixed() {
reprs.extend(param.meta_item().and_then(|mi| parse_repr(cx, &mi)));
if let Some(_) = param.lit() {
cx.emit_err(session_diagnostics::ReprIdent { span: cx.attr_span });
continue;
}

reprs.extend(
param.meta_item().and_then(|mi| parse_repr(cx, &mi)).map(|r| (r, param.span())),
);
}

reprs
Expand All @@ -58,7 +70,6 @@ macro_rules! int_pat {
};
}

// TODO: inline
fn int_type_of_word(s: Symbol) -> Option<IntType> {
use IntType::*;

Expand Down Expand Up @@ -88,7 +99,7 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr

match (ident.name, args) {
(sym::align, ArgParser::NoArgs) => {
cx.dcx().emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
cx.emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
None
}
(sym::align, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Align),
Expand All @@ -99,7 +110,7 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
}

(sym::align | sym::packed, ArgParser::NameValue(l)) => {
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatGeneric {
cx.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
span: param.span(),
// FIXME(jdonszelmann) can just be a string in the diag type
repr_arg: &ident.to_string(),
Expand All @@ -125,22 +136,22 @@ fn parse_repr(cx: &AcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<Repr
sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(),
ArgParser::NameValue(_),
) => {
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoValue {
cx.emit_err(session_diagnostics::InvalidReprHintNoValue {
span: param.span(),
name: ident.to_string(),
});
None
}
(sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::List(_)) => {
cx.dcx().emit_err(session_diagnostics::InvalidReprHintNoParen {
cx.emit_err(session_diagnostics::InvalidReprHintNoParen {
span: param.span(),
name: ident.to_string(),
});
None
}

_ => {
cx.dcx().emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
cx.emit_err(session_diagnostics::UnrecognizedReprHint { span: param.span() });
None
}
}
Expand All @@ -162,7 +173,7 @@ fn parse_repr_align(
let Some(align) = list.single() else {
match align_kind {
Packed => {
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
span: param_span,
});
}
Expand All @@ -179,12 +190,12 @@ fn parse_repr_align(
let Some(lit) = align.lit() else {
match align_kind {
Packed => {
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
span: align.span(),
});
}
Align => {
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
span: align.span(),
});
}
Expand All @@ -199,7 +210,7 @@ fn parse_repr_align(
AlignKind::Align => ReprAttr::ReprAlign(literal),
}),
Err(message) => {
cx.dcx().emit_err(session_diagnostics::InvalidReprGeneric {
cx.emit_err(session_diagnostics::InvalidReprGeneric {
span: lit.span,
repr_arg: match align_kind {
Packed => "packed".to_string(),
Expand Down
Loading

0 comments on commit 4aaff39

Please sign in to comment.