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 c5abf08 commit 4d3437f
Show file tree
Hide file tree
Showing 14 changed files with 26 additions and 102 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 @@ -141,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, 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 @@ -172,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 @@ -195,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, 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: 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
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ 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;
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/repr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ macro_rules! int_pat {
};
}

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

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 TransparencyParser;

// 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 SingleAttributeParser for TransparencyParser {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_attr_parsing/src/attributes/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub fn parse_version(s: Symbol) -> Option<RustcVersion> {
Some(RustcVersion { major, minor, patch })
}

// TODO: create single word attribute map
pub fn is_builtin_attr(attr: &impl AttributeExt) -> bool {
attr.is_doc_comment() || attr.ident().is_some_and(|ident| is_builtin_attr_name(ident.name))
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_attr_parsing/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rustc_fluent_macro::fluent_messages! { "../messages.ftl" }
///
/// A little like `matches` but for attributes.
///
/// ```rust,no_run
/// ```rust,ignore (illustrative)
/// // finds the repr attribute
/// if let Some(r) = find_attr!(attrs, AttributeKind::Repr(r) => r) {
///
Expand Down
34 changes: 13 additions & 21 deletions compiler/rustc_attr_parsing/src/parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::panic;
use std::fmt::{Debug, Display};
use std::iter::Peekable;

Expand Down Expand Up @@ -231,7 +230,7 @@ impl<'a> Debug for MetaItemParser<'a> {

impl<'a> MetaItemParser<'a> {
/// Create a new parser from a [`NormalAttr`], which is stored inside of any
/// [`ast::Attribute`](Attribute)
/// [`ast::Attribute`](rustc_ast::Attribute)
pub fn from_attr(attr: &'a NormalAttr, dcx: DiagCtxtHandle<'a>) -> Self {
Self {
path: PathParser::Ast(&attr.item.path),
Expand Down Expand Up @@ -268,8 +267,6 @@ impl<'a> MetaItemParser<'a> {
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path
/// - `#[allow(clippy::complexity)]`: `clippy::complexity` is a path
/// - `#[inline]`: `inline` is a single segment path
/// - `#[inline(always)]`: `always` is a single segment path, but `inline` is *not and
/// should be parsed using [`list`](Self::list)
pub fn path(&self) -> (PathParser<'a>, &ArgParser<'a>) {
self.deconstruct()
}
Expand All @@ -291,11 +288,8 @@ impl<'a> MetaItemParser<'a> {
///
/// Some examples:
/// - `#[inline]`: `inline` is a word
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path, and not a word
/// - `#[inline(always)]`: `always` is a word, but `inline` is *not and should be parsed
/// using [`path_list`](Self::path_list)
/// - `#[allow(clippy::complexity)]`: `clippy::complexity` is *not* a word, and should instead be parsed
/// using [`path`](Self::path)
/// - `#[rustfmt::skip]`: `rustfmt::skip` is a path,
/// and not a word and should instead be parsed using [`path`](Self::path)
pub fn word(&self) -> Option<(Ident, &ArgParser<'a>)> {
let (path, args) = self.deconstruct();
Some((path.word()?, args))
Expand Down Expand Up @@ -406,7 +400,7 @@ impl<'a> MetaItemListParserContext<'a> {
{
segments.push(Ident::new(name, span));
} else {
unreachable!()
return None;
}
if let Some(TokenTree::Token(Token { kind: token::PathSep, .. }, _)) =
self.inside_delimiters.peek()
Expand All @@ -422,16 +416,14 @@ impl<'a> MetaItemListParserContext<'a> {
Some(TokenTree::Token(
Token { kind: token::OpenDelim(_) | token::CloseDelim(_), .. },
_,
)) => {
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tt);
}
Some(x) => {
)) => None,
Some(_) => {
// malformed attributes can get here. We can't crash, but somewhere else should've
// already warned for this.
self.dcx.span_delayed_bug(
x.span(),
format!("unexpected token {x:?} in built-in attribute path"),
);
// self.dcx.span_delayed_bug(
// x.span(),
// format!("unexpected token {x:?} in built-in attribute path"),
// );
None
}
None => None,
Expand All @@ -450,7 +442,7 @@ impl<'a> MetaItemListParserContext<'a> {
Some(TokenTree::Token(ref token, _)) => {
if let Some(s) = MetaItemLit::from_token(token) { Some(s) } else { None }
}
x => unreachable!("{x:?}"),
x => None,
}
}

Expand Down Expand Up @@ -532,9 +524,9 @@ impl<'a> MetaItemListParserContext<'a> {
)),
}
}
Some(TokenTree::Delimited(span, ..)) => {
Some(TokenTree::Delimited(_, ..)) => {
self.inside_delimiters.next();
self.dcx.span_delayed_bug(span.entire(), "wrong delimiters");
// self.dcx.span_delayed_bug(span.entire(), "wrong delimiters");
return None;
}
Some(TokenTree::Token(Token { kind: token::Eq, span }, _)) => {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,7 @@ impl AttributeExt for Attribute {
Attribute::Unparsed(u) => u.span,
// FIXME: should not be needed anymore when all attrs are parsed
Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span,
Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span,
a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"),
}
}
Expand Down Expand Up @@ -1149,6 +1150,7 @@ impl AttributeExt for Attribute {
fn style(&self) -> AttrStyle {
match &self {
Attribute::Unparsed(u) => u.style,
Attribute::Parsed(AttributeKind::DocComment { style, .. }) => *style,
_ => panic!(),
}
}
Expand Down
4 changes: 0 additions & 4 deletions compiler/rustc_lint/src/expect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,6 @@ fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
// We are an `eval_always` query, so looking at the attribute's `AttrId` is ok.
let attr_id = tcx.hir().attrs(hir_id)[attr_index as usize].id();

// TODO: we're only dealling with allow/deny/etc lint attributes. They can have an
// ID, while other attributes don't necessarily. however, how do we assert that
// nicely?
// let attr_id = todo!();
(attr_id, lint_index)
}
_ => panic!("fulfilled expectations must have a lint index"),
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1767,8 +1767,6 @@ impl<'tcx> TyCtxt<'tcx> {
if let Some(did) = did.as_local() {
self.hir().attrs(self.local_def_id_to_hir_id(did)).iter()
} else {
// TODO: commented this check because we don't have the attr symbol from get_attrs here
// debug_assert!(rustc_feature::encode_cross_crate(attr));
self.attrs_for_def(did).iter()
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1868,7 +1868,7 @@ pub(crate) struct NoSanitize<'a> {
pub attr_str: &'a str,
}

// TODO: move back to rustc_attr
// FIXME(jdonszelmann): move back to rustc_attr
#[derive(Diagnostic)]
#[diag(passes_rustc_const_stable_indirect_pairing)]
pub(crate) struct RustcConstStableIndirectPairing {
Expand Down
4 changes: 1 addition & 3 deletions compiler/rustc_passes/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ impl<'a, 'tcx> Annotator<'a, 'tcx> {
}

if let Some(body_stab) = body_stab {
// TODO: check that this item can have body stability
// FIXME: check that this item can have body stability

self.index.default_body_stab_map.insert(def_id, body_stab);
debug!(?self.index.default_body_stab_map);
Expand Down Expand Up @@ -801,8 +801,6 @@ impl<'tcx> Visitor<'tcx> for Checker<'tcx> {
let features = self.tcx.features();
if features.staged_api() {
let attrs = self.tcx.hir().attrs(item.hir_id());
// TODO: check with https://github.com/rust-lang/rust/commit/e96808162ad7ff5906d7b58d32a25abe139e998c#diff-5f57ad10e1bdde3d046b258d390fd2ecc6f1511158aa130cebb72093da16ef29

let stab = attr::find_attr!(attrs, AttributeKind::Stability{stability, span} => (*stability, *span));

// FIXME(jdonszelmann): make it impossible to miss the or_else in the typesystem
Expand Down
6 changes: 5 additions & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2732,7 +2732,11 @@ fn add_without_unwanted_attributes<'hir>(
}
}
}
_ => unreachable!(),
hir::Attribute::Parsed(..) => {
if is_inline {
attrs.push((Cow::Owned(attr), import_parent));
}
}
}
}
}
Expand Down

0 comments on commit 4d3437f

Please sign in to comment.