Skip to content

Commit

Permalink
tests run, some fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jdonszelmann committed Dec 5, 2024
1 parent 81d7336 commit 322b8d2
Show file tree
Hide file tree
Showing 39 changed files with 656 additions and 597 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

use rustc_ast::node_id::NodeMap;
use rustc_ast::{self as ast, *};
use rustc_attr::AttributeParseContext;
use rustc_attr::{AttributeParseContext, OmitDoc};
use rustc_data_structures::captures::Captures;
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::sorted_map::SortedMap;
Expand Down Expand Up @@ -868,7 +868,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
}

fn lower_attrs_vec(&self, attrs: &[Attribute], target_span: Span) -> Vec<hir::Attribute> {
self.attribute_parse_context.parse_attribute_list(attrs, target_span)
self.attribute_parse_context.parse_attribute_list(attrs, target_span, OmitDoc::Lower)
}

fn alias_attrs(&mut self, id: HirId, target_id: HirId) {
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_ast_passes/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ ast_passes_precise_capturing_not_allowed_here = `use<...>` precise capturing syn
ast_passes_show_span = {$msg}
ast_passes_stability_outside_std = stability attributes may not be used outside of the standard library
ast_passes_static_without_body =
free static item without body
.suggestion = provide a definition for the static
Expand Down
7 changes: 0 additions & 7 deletions compiler/rustc_ast_passes/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,13 +733,6 @@ pub(crate) struct AssociatedSuggestion2 {
pub potential_assoc: Ident,
}

#[derive(Diagnostic)]
#[diag(ast_passes_stability_outside_std, code = E0734)]
pub(crate) struct StabilityOutsideStd {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_passes_feature_on_non_nightly, code = E0554)]
pub(crate) struct FeatureOnNonNightly {
Expand Down
12 changes: 0 additions & 12 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,18 +209,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
);
}
}

// Emit errors for non-staged-api crates.
if !self.features.staged_api() {
if attr.has_name(sym::unstable)
|| attr.has_name(sym::stable)
|| attr.has_name(sym::rustc_const_unstable)
|| attr.has_name(sym::rustc_const_stable)
|| attr.has_name(sym::rustc_default_body_unstable)
{
self.sess.dcx().emit_err(errors::StabilityOutsideStd { span: attr.span });
}
}
}

fn visit_item(&mut self, i: &'a ast::Item) {
Expand Down
16 changes: 11 additions & 5 deletions compiler/rustc_attr/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ attr_deprecated_item_suggestion =
.help = add `#![feature(deprecated_suggestion)]` to the crate root
.note = see #94785 for more details
attr_empty_confusables =
expected at least one confusable name
attr_expected_one_cfg_pattern =
expected 1 cfg-pattern
Expand All @@ -21,8 +23,8 @@ attr_expects_feature_list =
attr_expects_features =
`{$name}` expects feature names
attr_incorrect_meta_item =
incorrect meta item
attr_incorrect_meta_item = expected a quoted string literal
attr_incorrect_meta_item_suggestion = consider surrounding this with quotes
attr_incorrect_repr_format_align_one_arg =
incorrect `repr(align)` attribute format: `align` takes exactly one argument in parentheses
Expand Down Expand Up @@ -91,15 +93,14 @@ attr_non_ident_feature =
attr_rustc_allowed_unstable_pairing =
`rustc_allowed_through_unstable_modules` attribute must be paired with a `stable` attribute
attr_rustc_const_stable_indirect_pairing =
`const_stable_indirect` attribute does not make sense on `rustc_const_stable` function, its behavior is already implied
attr_rustc_promotable_pairing =
`rustc_promotable` attribute must be paired with either a `rustc_const_unstable` or a `rustc_const_stable` attribute
attr_soft_no_args =
`soft` should not have any arguments
attr_stability_outside_std = stability attributes may not be used outside of the standard library
attr_unknown_meta_item =
unknown meta item '{$item}'
.label = expected one of {$expected}
Expand All @@ -122,3 +123,8 @@ attr_unsupported_literal_generic =
unsupported literal
attr_unsupported_literal_suggestion =
consider removing the prefix
attr_unused_multiple =
multiple `{$name}` attributes
.suggestion = remove this attribute
.note = attribute also specified here
38 changes: 31 additions & 7 deletions compiler/rustc_attr/src/attributes/confusables.rs
Original file line number Diff line number Diff line change
@@ -1,39 +1,63 @@
use rustc_hir::AttributeKind;
use rustc_span::{Symbol, sym};
use rustc_span::{Span, Symbol, sym};
use thin_vec::ThinVec;

use super::{AttributeFilter, AttributeGroup, AttributeMapping};
use crate::attribute_filter;
use crate::context::AttributeGroupContext;
use crate::parser::ArgParser;
use crate::{attribute_filter, session_diagnostics};

// TODO: turn into CombineGroup?
#[derive(Default)]
pub(crate) struct ConfusablesGroup {
confusables: ThinVec<Symbol>,
first_span: Option<Span>,
}

impl AttributeGroup for ConfusablesGroup {
const ATTRIBUTES: AttributeMapping<Self> = &[(&[sym::rustc_confusables], |this, _cx, args| {
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.
// 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 });
}

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

let Some(lit) = param.lit() else {
// TODO: error when not a lit? Bring validation code here.
// curently silently ignored.
return;
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
span,
suggestion: Some(session_diagnostics::IncorrectMetaItemSuggestion {
lo: span.shrink_to_lo(),
hi: span.shrink_to_hi(),
}),
});
continue;
};

this.confusables.push(lit.symbol);
}

this.first_span.get_or_insert(cx.attr_span);
})];

fn finalize(self, _cx: &AttributeGroupContext<'_>) -> Option<(AttributeKind, AttributeFilter)> {
Some((AttributeKind::Confusables(self.confusables), attribute_filter!(allow all)))
if self.confusables.is_empty() {
return None;
}

Some((
AttributeKind::Confusables {
symbols: self.confusables,
first_span: self.first_span.unwrap(),
},
attribute_filter!(allow all),
))
}
}
19 changes: 12 additions & 7 deletions compiler/rustc_attr/src/attributes/deprecation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@ fn get<'a>(
false
}
} else {
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem { span: param_span });
// FIXME(jdonszelmann): suggestion?
cx.dcx().emit_err(session_diagnostics::IncorrectMetaItem {
span: param_span,
suggestion: None,
});
false
}
}

impl SingleAttributeGroup for DeprecationGroup {
const PATH: &'static [rustc_span::Symbol] = &[sym::deprecated];

fn on_duplicate(
_cx: &crate::context::AttributeAcceptContext<'_>,
_first_span: rustc_span::Span,
) {
// TODO: investigate duplicate deprecation attr
todo!()
fn on_duplicate(cx: &crate::context::AttributeAcceptContext<'_>, first_span: rustc_span::Span) {
// FIXME(jdonszelmann): merge with errors from check_attrs.rs
cx.dcx().emit_err(session_diagnostics::UnusedMultiple {
this: cx.attr_span,
other: first_span,
name: sym::deprecated,
});
}

fn convert(
Expand Down
Empty file.
1 change: 0 additions & 1 deletion compiler/rustc_attr/src/attributes/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ pub(crate) mod allow_unstable;
pub(crate) mod cfg;
pub(crate) mod confusables;
pub(crate) mod deprecation;
pub(crate) mod inline;
pub(crate) mod repr;
pub(crate) mod stability;
pub(crate) mod transparency;
Expand Down
Loading

0 comments on commit 322b8d2

Please sign in to comment.