Skip to content

Commit

Permalink
clean up TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Jan 20, 2025
1 parent d6c5c86 commit e920917
Show file tree
Hide file tree
Showing 19 changed files with 203 additions and 249 deletions.
65 changes: 1 addition & 64 deletions compiler/rustc_attr_data_structures/src/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,26 +142,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, Span)>),
AutoDiff,
AutomaticallyDerived,
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 @@ -173,14 +163,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 @@ -196,57 +178,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, 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
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::iter;

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

use super::{CombineAttributeGroup, ConvertFn};
use crate::context::AttributeAcceptContext;
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
3 changes: 1 addition & 2 deletions compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use rustc_attr_data_structures::AttributeKind;
use rustc_span::{Span, Symbol, sym};
use thin_vec::ThinVec;
Expand All @@ -17,7 +16,7 @@ pub(crate) struct ConfusablesGroup {
impl AttributeGroup for ConfusablesGroup {
const ATTRIBUTES: AttributeMapping<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;
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_attr_parsing/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ fn get(
}
} else {
// FIXME(jdonszelmann): suggestion?
cx.emit_err(session_diagnostics::IncorrectMetaItem {
span: param_span,
suggestion: None,
});
cx.emit_err(session_diagnostics::IncorrectMetaItem { span: param_span, suggestion: None });
false
}
}
Expand Down
7 changes: 1 addition & 6 deletions compiler/rustc_attr_parsing/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@ impl<T: CombineAttributeGroup> AttributeGroup for Combine<T> {
&[(T::PATH, |group: &mut Combine<T>, cx, args| group.1.extend(T::extend(cx, args)))];

fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<AttributeKind> {
if self.1.is_empty() {
None
} else {
// TODO: what filter here?
Some(T::CONVERT(self.1))
}
if self.1.is_empty() { None } else { Some(T::CONVERT(self.1)) }
}
}
87 changes: 42 additions & 45 deletions compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ impl CombineAttributeGroup for ReprGroup {

for param in list.mixed() {
if let Some(_) = param.lit() {
cx.emit_err(session_diagnostics::ReprIdent {
span: cx.attr_span,
});
cx.emit_err(session_diagnostics::ReprIdent { span: cx.attr_span });
continue;
}

Expand All @@ -57,22 +55,21 @@ impl CombineAttributeGroup for ReprGroup {

macro_rules! int_pat {
() => {
sym::i8
| sym::u8
| sym::i16
| sym::u16
| sym::i32
| sym::u32
| sym::i64
| sym::u64
| sym::i128
| sym::u128
| sym::isize
| sym::usize
sym::i8
| sym::u8
| sym::i16
| sym::u16
| sym::i32
| sym::u32
| sym::i64
| sym::u64
| sym::i128
| sym::u128
| sym::isize
| sym::usize
};
}

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

Expand All @@ -93,27 +90,26 @@ fn int_type_of_word(s: Symbol) -> Option<IntType> {
}
}

fn parse_repr(
cx: &AttributeAcceptContext<'_>,
param: &MetaItemParser<'_>,
) -> Option<ReprAttr> {
fn parse_repr(cx: &AttributeAcceptContext<'_>, param: &MetaItemParser<'_>) -> Option<ReprAttr> {
use ReprAttr::*;

// FIXME(jdonszelmann): invert the parsing here to match on the word first and then the
// structure.
let (ident, args) = param.word_or_empty();

match (ident.name, args) {
(sym::align, ArgParser::NoArgs) => {
(sym::align, ArgParser::NoArgs) => {
cx.emit_err(session_diagnostics::InvalidReprAlignNeedArg { span: ident.span });
None
}
(sym::align, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Align),

(sym::packed, ArgParser::NoArgs) => Some(ReprPacked(Align::ONE)),
(sym::packed, ArgParser::List(l)) => parse_repr_align(cx, l, param.span(), AlignKind::Packed),
(sym::packed, ArgParser::List(l)) => {
parse_repr_align(cx, l, param.span(), AlignKind::Packed)
}

(sym::align | sym::packed, ArgParser::NameValue(l)) => {
(sym::align | sym::packed, ArgParser::NameValue(l)) => {
cx.emit_err(session_diagnostics::IncorrectReprFormatGeneric {
span: param.span(),
// FIXME(jdonszelmann) can just be a string in the diag type
Expand All @@ -127,24 +123,19 @@ fn parse_repr(
None
}

(sym::Rust, ArgParser::NoArgs) => {
Some(ReprRust)
}
(sym::C, ArgParser::NoArgs) => {
Some(ReprC)
}
(sym::simd, ArgParser::NoArgs) => {
Some(ReprSimd)
}
(sym::transparent, ArgParser::NoArgs) => {
Some(ReprTransparent)
}
(i@int_pat!(), ArgParser::NoArgs) => {
(sym::Rust, ArgParser::NoArgs) => Some(ReprRust),
(sym::C, ArgParser::NoArgs) => Some(ReprC),
(sym::simd, ArgParser::NoArgs) => Some(ReprSimd),
(sym::transparent, ArgParser::NoArgs) => Some(ReprTransparent),
(i @ int_pat!(), ArgParser::NoArgs) => {
// int_pat!() should make sure it always parses
Some(ReprInt(int_type_of_word(i).unwrap()))
}

(sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(), ArgParser::NameValue(_)) => {
(
sym::Rust | sym::C | sym::simd | sym::transparent | int_pat!(),
ArgParser::NameValue(_),
) => {
cx.emit_err(session_diagnostics::InvalidReprHintNoValue {
span: param.span(),
name: ident.to_string(),
Expand All @@ -168,10 +159,15 @@ fn parse_repr(

enum AlignKind {
Packed,
Align
Align,
}

fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'_>, param_span: Span, align_kind: AlignKind) -> Option<ReprAttr> {
fn parse_repr_align(
cx: &AttributeAcceptContext<'_>,
list: &MetaItemListParser<'_>,
param_span: Span,
align_kind: AlignKind,
) -> Option<ReprAttr> {
use AlignKind::*;

let Some(align) = list.single() else {
Expand All @@ -180,14 +176,15 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedOneOrZeroArg {
span: param_span,
});
},
}
Align => {
cx.dcx()
.emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg { span: param_span });
cx.dcx().emit_err(session_diagnostics::IncorrectReprFormatAlignOneArg {
span: param_span,
});
}
}

return None
return None;
};

let Some(lit) = align.lit() else {
Expand All @@ -196,15 +193,15 @@ fn parse_repr_align(cx: &AttributeAcceptContext<'_>, list: &MetaItemListParser<'
cx.emit_err(session_diagnostics::IncorrectReprFormatPackedExpectInteger {
span: align.span(),
});
},
}
Align => {
cx.emit_err(session_diagnostics::IncorrectReprFormatExpectInteger {
span: align.span(),
});
}
}

return None
return None;
};

match parse_alignment(&lit.kind) {
Expand Down
27 changes: 18 additions & 9 deletions compiler/rustc_attr_parsing/src/attributes/stability.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use std::num::NonZero;

use rustc_attr_data_structures::{
AllowedThroughUnstableModules, AttributeKind, DefaultBodyStability, PartialConstStability, Stability, StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER
AllowedThroughUnstableModules, AttributeKind, DefaultBodyStability, PartialConstStability,
Stability, StabilityLevel, StableSince, UnstableReason, VERSION_PLACEHOLDER,
};
use rustc_span::{ErrorGuaranteed, Span, Symbol, sym};

Expand All @@ -16,7 +17,7 @@ macro_rules! reject_outside_std {
// Emit errors for non-staged-api crates.
if !$cx.features().staged_api() {
$cx.emit_err(session_diagnostics::StabilityOutsideStd { span: $cx.attr_span });
return
return;
}
};
}
Expand Down Expand Up @@ -59,16 +60,24 @@ impl AttributeGroup for StabilityGroup {
}),
(&[sym::rustc_allowed_through_unstable_modules], |this, cx, args| {
reject_outside_std!(cx);
this.allowed_through_unstable_modules = Some(match args.name_value().and_then(|i| i.value_as_str()) {
Some(msg) => AllowedThroughUnstableModules::WithDeprecation(msg),
None => AllowedThroughUnstableModules::WithoutDeprecation,
});
this.allowed_through_unstable_modules =
Some(match args.name_value().and_then(|i| i.value_as_str()) {
Some(msg) => AllowedThroughUnstableModules::WithDeprecation(msg),
None => AllowedThroughUnstableModules::WithoutDeprecation,
});
}),
];

fn finalize(mut self, cx: &AttributeGroupContext<'_>) -> Option<AttributeKind> {
if let Some(atum) = self.allowed_through_unstable_modules {
if let Some((Stability{level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. }, ..}, _)) = self.stability {
if let Some((
Stability {
level: StabilityLevel::Stable { ref mut allowed_through_unstable_modules, .. },
..
},
_,
)) = self.stability
{
*allowed_through_unstable_modules = Some(atum);
} else {
cx.dcx().emit_err(session_diagnostics::RustcAllowedUnstablePairing {
Expand Down Expand Up @@ -358,8 +367,8 @@ pub(crate) fn parse_unstability(
None => Err(cx.emit_err(session_diagnostics::MissingFeature { span: cx.attr_span })),
};

let issue = issue
.ok_or_else(|| cx.emit_err(session_diagnostics::MissingIssue { span: cx.attr_span }));
let issue =
issue.ok_or_else(|| cx.emit_err(session_diagnostics::MissingIssue { span: cx.attr_span }));

match (feature, issue) {
(Ok(feature), Ok(_)) => {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/transparency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::parser::ArgParser;

pub(crate) struct TransparencyGroup;

// TODO: fix this but I don't want to rn
// FIXME(jdonszelmann): make these proper diagnostics
#[allow(rustc::untranslatable_diagnostic)]
#[allow(rustc::diagnostic_outside_of_impl)]
impl SingleAttributeGroup for TransparencyGroup {
Expand Down
Loading

0 comments on commit e920917

Please sign in to comment.