Auto merge of #150079 - jhpratt:rollup-iehzejf, r=jhpratt

Rollup of 4 pull requests

Successful merges:

 - rust-lang/rust#150000 (Port `#[rustc_legacy_const_generics]` to use attribute parser )
 - rust-lang/rust#150060 (autodiff: emit an error if we fail to find libEnzyme)
 - rust-lang/rust#150070 (Partially revert rust-lang/rust#147888 and print warning if LLVM CMake dir is missing when building Enzyme)
 - rust-lang/rust#150072 (Port #[no_link] to use attribute parser)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2025-12-17 04:13:48 +00:00
commit ec6f62244c
26 changed files with 449 additions and 383 deletions

View file

@ -237,25 +237,27 @@ impl SpanLowerer {
#[extension(trait ResolverAstLoweringExt)]
impl ResolverAstLowering {
fn legacy_const_generic_args(&self, expr: &Expr) -> Option<Vec<usize>> {
if let ExprKind::Path(None, path) = &expr.kind {
// Don't perform legacy const generics rewriting if the path already
// has generic arguments.
if path.segments.last().unwrap().args.is_some() {
return None;
}
let ExprKind::Path(None, path) = &expr.kind else {
return None;
};
if let Res::Def(DefKind::Fn, def_id) = self.partial_res_map.get(&expr.id)?.full_res()? {
// We only support cross-crate argument rewriting. Uses
// within the same crate should be updated to use the new
// const generics style.
if def_id.is_local() {
return None;
}
// Don't perform legacy const generics rewriting if the path already
// has generic arguments.
if path.segments.last().unwrap().args.is_some() {
return None;
}
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
return v.clone();
}
}
let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
// We only support cross-crate argument rewriting. Uses
// within the same crate should be updated to use the new
// const generics style.
if def_id.is_local() {
return None;
}
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
return v.clone();
}
None

View file

@ -47,6 +47,7 @@ pub(crate) mod loop_match;
pub(crate) mod macro_attrs;
pub(crate) mod must_use;
pub(crate) mod no_implicit_prelude;
pub(crate) mod no_link;
pub(crate) mod non_exhaustive;
pub(crate) mod path;
pub(crate) mod pin_v2;

View file

@ -0,0 +1,14 @@
use super::prelude::*;
pub(crate) struct NoLinkParser;
impl<S: Stage> NoArgsAttributeParser<S> for NoLinkParser {
const PATH: &[Symbol] = &[sym::no_link];
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
Allow(Target::ExternCrate),
Warn(Target::Field),
Warn(Target::Arm),
Warn(Target::MacroDef),
]);
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::NoLink;
}

View file

@ -1,3 +1,5 @@
use rustc_ast::{LitIntType, LitKind, MetaItemLit};
use super::prelude::*;
use super::util::parse_single_integer;
use crate::session_diagnostics::RustcScalableVectorCountOutOfRange;
@ -41,6 +43,50 @@ impl<S: Stage> SingleAttributeParser<S> for RustcLayoutScalarValidRangeEndParser
}
}
pub(crate) struct RustcLegacyConstGenericsParser;
impl<S: Stage> SingleAttributeParser<S> for RustcLegacyConstGenericsParser {
const PATH: &[Symbol] = &[sym::rustc_legacy_const_generics];
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost;
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]);
const TEMPLATE: AttributeTemplate = template!(List: &["N"]);
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
let ArgParser::List(meta_items) = args else {
cx.expected_list(cx.attr_span, args);
return None;
};
let mut parsed_indexes = ThinVec::new();
let mut errored = false;
for possible_index in meta_items.mixed() {
if let MetaItemOrLitParser::Lit(MetaItemLit {
kind: LitKind::Int(index, LitIntType::Unsuffixed),
..
}) = possible_index
{
parsed_indexes.push((index.0 as usize, possible_index.span()));
} else {
cx.expected_integer_literal(possible_index.span());
errored = true;
}
}
if errored {
return None;
} else if parsed_indexes.is_empty() {
cx.expected_at_least_one_argument(args.span()?);
return None;
}
Some(AttributeKind::RustcLegacyConstGenerics {
fn_indexes: parsed_indexes,
attr_span: cx.attr_span,
})
}
}
pub(crate) struct RustcObjectLifetimeDefaultParser;
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {

View file

@ -50,6 +50,7 @@ use crate::attributes::macro_attrs::{
};
use crate::attributes::must_use::MustUseParser;
use crate::attributes::no_implicit_prelude::NoImplicitPreludeParser;
use crate::attributes::no_link::NoLinkParser;
use crate::attributes::non_exhaustive::NonExhaustiveParser;
use crate::attributes::path::PathParser as PathAttributeParser;
use crate::attributes::pin_v2::PinV2Parser;
@ -59,9 +60,9 @@ use crate::attributes::proc_macro_attrs::{
use crate::attributes::prototype::CustomMirParser;
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
use crate::attributes::rustc_internal::{
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser, RustcMainParser,
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
RustcSimdMonomorphizeLaneLimitParser,
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
RustcLegacyConstGenericsParser, RustcMainParser, RustcObjectLifetimeDefaultParser,
RustcScalableVectorParser, RustcSimdMonomorphizeLaneLimitParser,
};
use crate::attributes::semantics::MayDangleParser;
use crate::attributes::stability::{
@ -209,6 +210,7 @@ attribute_parsers!(
Single<RustcForceInlineParser>,
Single<RustcLayoutScalarValidRangeEndParser>,
Single<RustcLayoutScalarValidRangeStartParser>,
Single<RustcLegacyConstGenericsParser>,
Single<RustcObjectLifetimeDefaultParser>,
Single<RustcScalableVectorParser>,
Single<RustcSimdMonomorphizeLaneLimitParser>,
@ -240,6 +242,7 @@ attribute_parsers!(
Single<WithoutArgs<MayDangleParser>>,
Single<WithoutArgs<NoCoreParser>>,
Single<WithoutArgs<NoImplicitPreludeParser>>,
Single<WithoutArgs<NoLinkParser>>,
Single<WithoutArgs<NoMangleParser>>,
Single<WithoutArgs<NoStdParser>>,
Single<WithoutArgs<NonExhaustiveParser>>,

View file

@ -1,9 +1,10 @@
codegen_llvm_autodiff_component_unavailable = failed to load our autodiff backend. Did you install it via rustup?
codegen_llvm_autodiff_without_enable = using the autodiff feature requires -Z autodiff=Enable
codegen_llvm_autodiff_without_lto = using the autodiff feature requires setting `lto="fat"` in your Cargo.toml
codegen_llvm_copy_bitcode = failed to copy bitcode to object file: {$err}
codegen_llvm_fixed_x18_invalid_arch = the `-Zfixed-x18` flag is not supported on the `{$arch}` architecture
codegen_llvm_from_llvm_diag = {$message}

View file

@ -32,6 +32,11 @@ impl<G: EmissionGuarantee> Diagnostic<'_, G> for ParseTargetMachineConfig<'_> {
}
}
#[cfg(feature = "llvm_enzyme")]
#[derive(Diagnostic)]
#[diag(codegen_llvm_autodiff_component_unavailable)]
pub(crate) struct AutoDiffComponentUnavailable;
#[derive(Diagnostic)]
#[diag(codegen_llvm_autodiff_without_lto)]
pub(crate) struct AutoDiffWithoutLto;

View file

@ -13,6 +13,7 @@
#![feature(impl_trait_in_assoc_type)]
#![feature(iter_intersperse)]
#![feature(macro_derive)]
#![feature(once_cell_try)]
#![feature(trim_prefix_suffix)]
#![feature(try_blocks)]
// tidy-alphabetical-end
@ -247,7 +248,9 @@ impl CodegenBackend for LlvmCodegenBackend {
use crate::back::lto::enable_autodiff_settings;
if sess.opts.unstable_opts.autodiff.contains(&AutoDiff::Enable) {
drop(llvm::EnzymeWrapper::get_or_init(&sess.opts.sysroot));
if let Err(_) = llvm::EnzymeWrapper::get_or_init(&sess.opts.sysroot) {
sess.dcx().emit_fatal(crate::errors::AutoDiffComponentUnavailable);
}
enable_autodiff_settings(&sess.opts.unstable_opts.autodiff);
}
}

View file

@ -199,15 +199,13 @@ pub(crate) mod Enzyme_AD {
/// Safe to call multiple times - subsequent calls are no-ops due to OnceLock.
pub(crate) fn get_or_init(
sysroot: &rustc_session::config::Sysroot,
) -> MutexGuard<'static, Self> {
ENZYME_INSTANCE
.get_or_init(|| {
Self::call_dynamic(sysroot)
.unwrap_or_else(|e| bug!("failed to load Enzyme: {e}"))
.into()
})
.lock()
.unwrap()
) -> Result<MutexGuard<'static, Self>, Box<dyn std::error::Error>> {
let mtx: &'static Mutex<EnzymeWrapper> = ENZYME_INSTANCE.get_or_try_init(|| {
let w = Self::call_dynamic(sysroot)?;
Ok::<_, Box<dyn std::error::Error>>(Mutex::new(w))
})?;
Ok(mtx.lock().unwrap())
}
/// Get the EnzymeWrapper instance. Panics if not initialized.
@ -475,7 +473,7 @@ pub(crate) mod Fallback_AD {
impl EnzymeWrapper {
pub(crate) fn get_or_init(
_sysroot: &rustc_session::config::Sysroot,
) -> MutexGuard<'static, Self> {
) -> Result<MutexGuard<'static, Self>, Box<dyn std::error::Error>> {
unimplemented!("Enzyme not available: build with llvm_enzyme feature")
}

View file

@ -803,6 +803,9 @@ pub enum AttributeKind {
/// Represents `#[no_implicit_prelude]`
NoImplicitPrelude(Span),
/// Represents `#[no_link]`
NoLink,
/// Represents `#[no_mangle]`
NoMangle(Span),
@ -869,6 +872,9 @@ pub enum AttributeKind {
/// Represents `#[rustc_layout_scalar_valid_range_start]`.
RustcLayoutScalarValidRangeStart(Box<u128>, Span),
/// Represents `#[rustc_legacy_const_generics]`
RustcLegacyConstGenerics { fn_indexes: ThinVec<(usize, Span)>, attr_span: Span },
/// Represents `#[rustc_main]`.
RustcMain,

View file

@ -70,6 +70,7 @@ impl AttributeKind {
Naked(..) => No,
NoCore(..) => No,
NoImplicitPrelude(..) => No,
NoLink => No,
NoMangle(..) => Yes, // Needed for rustdoc
NoStd(..) => No,
NonExhaustive(..) => Yes, // Needed for rustdoc
@ -92,6 +93,7 @@ impl AttributeKind {
RustcCoherenceIsCore(..) => No,
RustcLayoutScalarValidRangeEnd(..) => Yes,
RustcLayoutScalarValidRangeStart(..) => Yes,
RustcLegacyConstGenerics { .. } => Yes,
RustcMain => No,
RustcObjectLifetimeDefault => No,
RustcPassIndirectlyInNonRusticAbis(..) => No,

View file

@ -169,7 +169,7 @@ macro_rules! print_tup {
print_tup!(A B C D E F G H);
print_skip!(Span, (), ErrorGuaranteed);
print_disp!(u16, u128, bool, NonZero<u32>, Limit);
print_disp!(u16, u128, usize, bool, NonZero<u32>, Limit);
print_debug!(
Symbol,
Ident,

View file

@ -197,7 +197,6 @@ pub struct ResolverGlobalCtxt {
#[derive(Debug)]
pub struct ResolverAstLowering {
pub legacy_const_generic_args: FxHashMap<DefId, Option<Vec<usize>>>,
/// Resolutions for nodes that have a single resolution.
pub partial_res_map: NodeMap<hir::def::PartialRes>,
/// Resolutions for import nodes, which have multiple resolutions in different namespaces.

View file

@ -240,11 +240,6 @@ passes_has_incoherent_inherent_impl =
`rustc_has_incoherent_inherent_impls` attribute should be applied to types or traits
.label = only adts, extern types and traits are supported
passes_ignored_attr_with_macro =
`#[{$sym}]` is ignored on struct fields, match arms and macro defs
.warn = {-passes_previously_accepted}
.note = {-passes_see_issue(issue: "80564")}
passes_ignored_derived_impls =
`{$name}` has {$trait_list_len ->
[one] a derived impl
@ -379,10 +374,6 @@ passes_must_not_suspend =
`must_not_suspend` attribute should be applied to a struct, enum, union, or trait
.label = is not a struct, enum, union, or trait
passes_no_link =
attribute should be applied to an `extern crate` item
.label = not an `extern crate` item
passes_no_main_function =
`main` function not found in crate `{$crate_name}`
.here_is_main = here is a function named `main`
@ -478,9 +469,6 @@ passes_rustc_legacy_const_generics_index_exceed =
*[other] arguments
}
passes_rustc_legacy_const_generics_index_negative =
arguments should be non-negative integers
passes_rustc_legacy_const_generics_only =
#[rustc_legacy_const_generics] functions must only have const generics
.label = non-const generic parameter

View file

@ -10,9 +10,10 @@ use std::collections::hash_map::Entry;
use std::slice;
use rustc_abi::{Align, ExternAbi, Size};
use rustc_ast::{AttrStyle, LitKind, MetaItemKind, ast};
use rustc_ast::{AttrStyle, MetaItemKind, ast};
use rustc_attr_parsing::{AttributeParser, Late};
use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::{DiagCtxtHandle, IntoDiagArg, MultiSpan, StashKey};
use rustc_feature::{
ACCEPTED_LANG_FEATURES, AttributeDuplicates, AttributeType, BUILTIN_ATTRIBUTE_MAP,
@ -211,6 +212,9 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
Attribute::Parsed(AttributeKind::MacroExport { span, .. }) => {
self.check_macro_export(hir_id, *span, target)
},
Attribute::Parsed(AttributeKind::RustcLegacyConstGenerics{attr_span, fn_indexes}) => {
self.check_rustc_legacy_const_generics(item, *attr_span, fn_indexes)
},
Attribute::Parsed(AttributeKind::Doc(attr)) => self.check_doc_attrs(attr, hir_id, target),
Attribute::Parsed(AttributeKind::EiiImpls(impls)) => {
self.check_eii_impl(impls, target)
@ -250,6 +254,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
| AttributeKind::LinkSection { .. }
| AttributeKind::MacroUse { .. }
| AttributeKind::MacroEscape( .. )
| AttributeKind::NoLink
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
| AttributeKind::RustcScalableVector { .. }
@ -299,16 +304,12 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
}
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
[sym::no_link, ..] => self.check_no_link(hir_id, attr, span, target),
[sym::rustc_no_implicit_autorefs, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
}
[sym::rustc_never_returns_null_ptr, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
}
[sym::rustc_legacy_const_generics, ..] => {
self.check_rustc_legacy_const_generics(hir_id, attr, span, target, item)
}
[sym::rustc_lint_query_instability, ..] => {
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
}
@ -456,15 +457,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
self.check_mix_no_mangle_export(hir_id, attrs);
}
fn inline_attr_str_error_with_macro_def(&self, hir_id: HirId, attr_span: Span, sym: &str) {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr_span,
errors::IgnoredAttrWithMacro { sym },
);
}
fn check_eii_impl(&self, impls: &[EiiImpl], target: Target) {
for EiiImpl { span, inner_span, eii_macro, impl_marked_unsafe, is_default: _ } in impls {
match target {
@ -1198,53 +1190,20 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
);
}
/// Checks if `#[no_link]` is applied to an `extern crate`.
fn check_no_link(&self, hir_id: HirId, attr: &Attribute, span: Span, target: Target) {
match target {
Target::ExternCrate => {}
// FIXME(#80564): We permit struct fields, match arms and macro defs to have an
// `#[no_link]` attribute with just a lint, because we previously
// erroneously allowed it and some crates used it accidentally, to be compatible
// with crates depending on them, we can't throw an error here.
Target::Field | Target::Arm | Target::MacroDef => {
self.inline_attr_str_error_with_macro_def(hir_id, attr.span(), "no_link");
}
_ => {
self.dcx().emit_err(errors::NoLink { attr_span: attr.span(), span });
}
}
}
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
fn check_rustc_legacy_const_generics(
&self,
hir_id: HirId,
attr: &Attribute,
span: Span,
target: Target,
item: Option<ItemLike<'_>>,
attr_span: Span,
index_list: &ThinVec<(usize, Span)>,
) {
let is_function = matches!(target, Target::Fn);
if !is_function {
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
attr_span: attr.span(),
defn_span: span,
on_crate: hir_id == CRATE_HIR_ID,
});
return;
}
let Some(list) = attr.meta_item_list() else {
// The attribute form is validated on AST.
return;
};
let Some(ItemLike::Item(Item {
kind: ItemKind::Fn { sig: FnSig { decl, .. }, generics, .. },
..
})) = item
else {
bug!("should be a function item");
// No error here, since it's already given by the parser
return;
};
for param in generics.params {
@ -1252,7 +1211,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
hir::GenericParamKind::Const { .. } => {}
_ => {
self.dcx().emit_err(errors::RustcLegacyConstGenericsOnly {
attr_span: attr.span(),
attr_span,
param_span: param.span,
});
return;
@ -1260,34 +1219,23 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
}
}
if list.len() != generics.params.len() {
if index_list.len() != generics.params.len() {
self.dcx().emit_err(errors::RustcLegacyConstGenericsIndex {
attr_span: attr.span(),
attr_span,
generics_span: generics.span,
});
return;
}
let arg_count = decl.inputs.len() as u128 + generics.params.len() as u128;
let mut invalid_args = vec![];
for meta in list {
if let Some(LitKind::Int(val, _)) = meta.lit().map(|lit| &lit.kind) {
if *val >= arg_count {
let span = meta.span();
self.dcx().emit_err(errors::RustcLegacyConstGenericsIndexExceed {
span,
arg_count: arg_count as usize,
});
return;
}
} else {
invalid_args.push(meta.span());
let arg_count = decl.inputs.len() + generics.params.len();
for (index, span) in index_list {
if *index >= arg_count {
self.dcx().emit_err(errors::RustcLegacyConstGenericsIndexExceed {
span: *span,
arg_count,
});
}
}
if !invalid_args.is_empty() {
self.dcx().emit_err(errors::RustcLegacyConstGenericsIndexNegative { invalid_args });
}
}
/// Helper function for checking that the provided attribute is only applied to a function or

View file

@ -80,12 +80,6 @@ pub(crate) struct OuterCrateLevelAttrSuggestion {
#[diag(passes_inner_crate_level_attr)]
pub(crate) struct InnerCrateLevelAttr;
#[derive(LintDiagnostic)]
#[diag(passes_ignored_attr_with_macro)]
pub(crate) struct IgnoredAttrWithMacro<'a> {
pub sym: &'a str,
}
#[derive(Diagnostic)]
#[diag(passes_should_be_applied_to_fn)]
pub(crate) struct AttrShouldBeAppliedToFn {
@ -254,15 +248,6 @@ pub(crate) struct Link {
pub span: Option<Span>,
}
#[derive(Diagnostic)]
#[diag(passes_no_link)]
pub(crate) struct NoLink {
#[primary_span]
pub attr_span: Span,
#[label]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(passes_rustc_legacy_const_generics_only)]
pub(crate) struct RustcLegacyConstGenericsOnly {
@ -290,13 +275,6 @@ pub(crate) struct RustcLegacyConstGenericsIndexExceed {
pub arg_count: usize,
}
#[derive(Diagnostic)]
#[diag(passes_rustc_legacy_const_generics_index_negative)]
pub(crate) struct RustcLegacyConstGenericsIndexNegative {
#[primary_span]
pub invalid_args: Vec<Span>,
}
#[derive(Diagnostic)]
#[diag(passes_rustc_dirty_clean)]
pub(crate) struct RustcDirtyClean {

View file

@ -43,7 +43,7 @@ use rustc_arena::{DroplessArena, TypedArena};
use rustc_ast::node_id::NodeMap;
use rustc_ast::{
self as ast, AngleBracketedArg, CRATE_NODE_ID, Crate, Expr, ExprKind, GenericArg, GenericArgs,
LitKind, NodeId, Path, attr,
NodeId, Path, attr,
};
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet};
use rustc_data_structures::intern::Interned;
@ -53,7 +53,7 @@ use rustc_data_structures::unord::{UnordMap, UnordSet};
use rustc_errors::{Applicability, Diag, ErrCode, ErrorGuaranteed, LintBuffer};
use rustc_expand::base::{DeriveResolution, SyntaxExtension, SyntaxExtensionKind};
use rustc_feature::BUILTIN_ATTRIBUTES;
use rustc_hir::attrs::StrippedCfgItem;
use rustc_hir::attrs::{AttributeKind, StrippedCfgItem};
use rustc_hir::def::Namespace::{self, *};
use rustc_hir::def::{
self, CtorOf, DefKind, DocLinkResMap, LifetimeRes, MacroKinds, NonMacroAttrKind, PartialRes,
@ -61,7 +61,7 @@ use rustc_hir::def::{
};
use rustc_hir::def_id::{CRATE_DEF_ID, CrateNum, DefId, LOCAL_CRATE, LocalDefId, LocalDefIdMap};
use rustc_hir::definitions::DisambiguatorState;
use rustc_hir::{PrimTy, TraitCandidate};
use rustc_hir::{PrimTy, TraitCandidate, find_attr};
use rustc_index::bit_set::DenseBitSet;
use rustc_metadata::creader::CStore;
use rustc_middle::metadata::{AmbigModChild, ModChild, Reexport};
@ -1675,8 +1675,8 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
node_id_to_def_id,
disambiguator: DisambiguatorState::new(),
placeholder_field_indices: Default::default(),
invocation_parents,
legacy_const_generic_args: Default::default(),
invocation_parents,
item_generics_num_lifetimes: Default::default(),
trait_impls: Default::default(),
confused_type_with_std_module: Default::default(),
@ -2395,40 +2395,33 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
/// `#[rustc_legacy_const_generics]` and returns the argument index list
/// from the attribute.
fn legacy_const_generic_args(&mut self, expr: &Expr) -> Option<Vec<usize>> {
if let ExprKind::Path(None, path) = &expr.kind {
// Don't perform legacy const generics rewriting if the path already
// has generic arguments.
if path.segments.last().unwrap().args.is_some() {
return None;
}
let res = self.partial_res_map.get(&expr.id)?.full_res()?;
if let Res::Def(def::DefKind::Fn, def_id) = res {
// We only support cross-crate argument rewriting. Uses
// within the same crate should be updated to use the new
// const generics style.
if def_id.is_local() {
return None;
}
if let Some(v) = self.legacy_const_generic_args.get(&def_id) {
return v.clone();
}
let attr = self.tcx.get_attr(def_id, sym::rustc_legacy_const_generics)?;
let mut ret = Vec::new();
for meta in attr.meta_item_list()? {
match meta.lit()?.kind {
LitKind::Int(a, _) => ret.push(a.get() as usize),
_ => panic!("invalid arg index"),
}
}
// Cache the lookup to avoid parsing attributes for an item multiple times.
self.legacy_const_generic_args.insert(def_id, Some(ret.clone()));
return Some(ret);
}
let ExprKind::Path(None, path) = &expr.kind else {
return None;
};
// Don't perform legacy const generics rewriting if the path already
// has generic arguments.
if path.segments.last().unwrap().args.is_some() {
return None;
}
None
let def_id = self.partial_res_map.get(&expr.id)?.full_res()?.opt_def_id()?;
// We only support cross-crate argument rewriting. Uses
// within the same crate should be updated to use the new
// const generics style.
if def_id.is_local() {
return None;
}
let indexes = find_attr!(
// we can use parsed attrs here since for other crates they're already available
self.tcx.get_all_attrs(def_id),
AttributeKind::RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes
)
.map(|fn_indexes| fn_indexes.iter().map(|(num, _)| *num).collect());
self.legacy_const_generic_args.insert(def_id, indexes.clone());
indexes
}
fn resolve_main(&mut self) {

View file

@ -925,7 +925,7 @@ impl Step for Enzyme {
}
let target = self.target;
let LlvmResult { host_llvm_config, .. } = builder.ensure(Llvm { target: self.target });
let LlvmResult { host_llvm_config, llvm_cmake_dir } = builder.ensure(Llvm { target });
static STAMP_HASH_MEMO: OnceLock<String> = OnceLock::new();
let smart_stamp_hash = STAMP_HASH_MEMO.get_or_init(|| {
@ -955,15 +955,20 @@ impl Step for Enzyme {
return out_dir;
}
if !builder.config.dry_run() && !llvm_cmake_dir.is_dir() {
builder.info(&format!(
"WARNING: {} does not exist, Enzyme build will likely fail",
llvm_cmake_dir.display()
));
}
trace!(?target, "(re)building enzyme artifacts");
builder.info(&format!("Building Enzyme for {target}"));
t!(stamp.remove());
let _time = helpers::timeit(builder);
t!(fs::create_dir_all(&out_dir));
builder
.config
.update_submodule(Path::new("src").join("tools").join("enzyme").to_str().unwrap());
builder.config.update_submodule("src/tools/enzyme");
let mut cfg = cmake::Config::new(builder.src.join("src/tools/enzyme/enzyme/"));
configure_cmake(builder, target, &mut cfg, true, LdFlags::default(), &[]);
@ -983,7 +988,7 @@ impl Step for Enzyme {
.define("LLVM_ENABLE_ASSERTIONS", "ON")
.define("ENZYME_EXTERNAL_SHARED_LIB", "ON")
.define("ENZYME_BC_LOADER", "OFF")
.define("LLVM_DIR", builder.llvm_out(target));
.define("LLVM_DIR", llvm_cmake_dir);
cfg.build();

View file

@ -117,7 +117,7 @@ pub fn check_incompatible_options_for_ci_llvm(
enable_warnings,
download_ci_llvm: _,
build_config,
enzyme: _,
enzyme,
} = ci_llvm_config;
err!(current_llvm_config.optimize, optimize);
@ -139,6 +139,7 @@ pub fn check_incompatible_options_for_ci_llvm(
err!(current_llvm_config.clang, clang);
err!(current_llvm_config.build_config, build_config);
err!(current_llvm_config.plugins, plugins);
err!(current_llvm_config.enzyme, enzyme);
warn!(current_llvm_config.enable_warnings, enable_warnings);

View file

@ -1,7 +1,7 @@
//! This module defines the primary IR[^1] used in rustdoc together with the procedures that
//! transform rustc data types into it.
//!
//! This IR — commonly referred to as the *cleaned AST* — is modeled after the [AST][ast].
//! This IR — commonly referred to as the *cleaned AST* — is modeled after the [AST][rustc_ast].
//!
//! There are two kinds of transformation — *cleaning* — procedures:
//!
@ -38,6 +38,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap, FxIndexSet, In
use rustc_data_structures::thin_vec::ThinVec;
use rustc_errors::codes::*;
use rustc_errors::{FatalError, struct_span_code_err};
use rustc_hir as hir;
use rustc_hir::attrs::{AttributeKind, DocAttribute, DocInline};
use rustc_hir::def::{CtorKind, DefKind, MacroKinds, Res};
use rustc_hir::def_id::{DefId, DefIdMap, DefIdSet, LOCAL_CRATE, LocalDefId};
@ -54,7 +55,6 @@ use rustc_span::symbol::{Ident, Symbol, kw, sym};
use rustc_trait_selection::traits::wf::object_region_bounds;
use tracing::{debug, instrument};
use utils::*;
use {rustc_ast as ast, rustc_hir as hir};
pub(crate) use self::cfg::{CfgInfo, extract_cfg_from_attrs};
pub(crate) use self::types::*;
@ -1026,26 +1026,20 @@ fn clean_fn_or_proc_macro<'tcx>(
/// `rustc_legacy_const_generics`. More information in
/// <https://github.com/rust-lang/rust/issues/83167>.
fn clean_fn_decl_legacy_const_generics(func: &mut Function, attrs: &[hir::Attribute]) {
for meta_item_list in attrs
.iter()
.filter(|a| a.has_name(sym::rustc_legacy_const_generics))
.filter_map(|a| a.meta_item_list())
{
for (pos, literal) in meta_item_list.iter().filter_map(|meta| meta.lit()).enumerate() {
match literal.kind {
ast::LitKind::Int(a, _) => {
let GenericParamDef { name, kind, .. } = func.generics.params.remove(0);
if let GenericParamDefKind::Const { ty, .. } = kind {
func.decl.inputs.insert(
a.get() as _,
Parameter { name: Some(name), type_: *ty, is_const: true },
);
} else {
panic!("unexpected non const in position {pos}");
}
}
_ => panic!("invalid arg index"),
}
let Some(indexes) =
find_attr!(attrs, AttributeKind::RustcLegacyConstGenerics{fn_indexes,..} => fn_indexes)
else {
return;
};
for (pos, (index, _)) in indexes.iter().enumerate() {
let GenericParamDef { name, kind, .. } = func.generics.params.remove(0);
if let GenericParamDefKind::Const { ty, .. } = kind {
func.decl
.inputs
.insert(*index, Parameter { name: Some(name), type_: *ty, is_const: true });
} else {
panic!("unexpected non const in position {pos}");
}
}
}

View file

@ -147,14 +147,6 @@ error: malformed `thread_local` attribute input
LL | #[thread_local()]
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[thread_local]`
error: malformed `no_link` attribute input
--> $DIR/malformed-attrs.rs:214:1
|
LL | #[no_link()]
| ^^^^^^^^^^^^ help: must be of the form: `#[no_link]`
|
= note: for more information, visit <https://doc.rust-lang.org/reference/items/extern-crates.html#the-no_link-attribute>
error: the `#[proc_macro]` attribute is only usable with crates of the `proc-macro` crate type
--> $DIR/malformed-attrs.rs:105:1
|
@ -626,6 +618,15 @@ LL | #[non_exhaustive = 1]
| | didn't expect any arguments here
| help: must be of the form: `#[non_exhaustive]`
error[E0565]: malformed `no_link` attribute input
--> $DIR/malformed-attrs.rs:214:1
|
LL | #[no_link()]
| ^^^^^^^^^--^
| | |
| | didn't expect any arguments here
| help: must be of the form: `#[no_link]`
error[E0539]: malformed `macro_use` attribute input
--> $DIR/malformed-attrs.rs:216:1
|

View file

@ -1,4 +1,3 @@
//~ NOTE: not an `extern crate` item
// This is testing whether various builtin attributes signals an
// error or warning when put in "weird" places.
//
@ -29,7 +28,7 @@
//~| WARN cannot be used on crates
//~| WARN previously accepted
#![no_link]
//~^ ERROR: attribute should be applied to an `extern crate` item
//~^ ERROR: `#[no_link]` attribute cannot be used on crates
#![export_name = "2200"]
//~^ ERROR: attribute cannot be used on
//~| NOTE takes precedence
@ -60,29 +59,40 @@ mod inline {
}
#[no_link]
//~^ ERROR attribute should be applied to an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on modules
mod no_link {
//~^ NOTE not an `extern crate` item
mod inner { #![no_link] }
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on modules
#[no_link] fn f() { }
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
#[no_link] fn f() {
//~^ ERROR `#[no_link]` attribute cannot be used on functions
match () {
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on match arms [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
_ => ()
}
}
#[no_link] struct S;
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
#[no_link]
//~^ ERROR `#[no_link]` attribute cannot be used on structs
struct S {
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on struct fields [unused_attributes]
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
field: ()
}
#[no_link]type T = S;
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on type aliases
#[no_link] impl S { }
//~^ ERROR attribute should be applied to an `extern crate` item
//~| NOTE not an `extern crate` item
//~^ ERROR `#[no_link]` attribute cannot be used on inherent impl blocks
#[no_link]
//~^ WARN `#[no_link]` attribute cannot be used on macro defs
//~| WARN this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
macro_rules! m{() => {}}
}
#[export_name = "2200"]

View file

@ -1,5 +1,5 @@
error[E0658]: use of an internal attribute
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:11:1
|
LL | #![rustc_main]
| ^^^^^^^^^^^^^^
@ -9,7 +9,7 @@ LL | #![rustc_main]
= note: the `#[rustc_main]` attribute is used internally to specify test entry point function
error: `#[macro_export]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:10:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:9:1
|
LL | #![macro_export]
| ^^^^^^^^^^^^^^^^
@ -17,7 +17,7 @@ LL | #![macro_export]
= help: `#[macro_export]` can only be applied to macro defs
error: `#[rustc_main]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:11:1
|
LL | #![rustc_main]
| ^^^^^^^^^^^^^^
@ -25,7 +25,7 @@ LL | #![rustc_main]
= help: `#[rustc_main]` can only be applied to functions
error: `#[path]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:21:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:20:1
|
LL | #![path = "3800"]
| ^^^^^^^^^^^^^^^^^
@ -33,15 +33,23 @@ LL | #![path = "3800"]
= help: `#[path]` can only be applied to modules
error: `#[automatically_derived]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:23:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:22:1
|
LL | #![automatically_derived]
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[automatically_derived]` can only be applied to trait impl blocks
error: `#[no_link]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:30:1
|
LL | #![no_link]
| ^^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[export_name]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:33:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1
|
LL | #![export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -49,7 +57,7 @@ LL | #![export_name = "2200"]
= help: `#[export_name]` can be applied to functions and statics
error: `#[inline]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:36:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:35:1
|
LL | #![inline]
| ^^^^^^^^^^
@ -57,7 +65,7 @@ LL | #![inline]
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:38:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:37:1
|
LL | #[inline]
| ^^^^^^^^^
@ -65,7 +73,7 @@ LL | #[inline]
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:43:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:42:17
|
LL | mod inner { #![inline] }
| ^^^^^^^^^^
@ -73,7 +81,7 @@ LL | mod inner { #![inline] }
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:52:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:51:5
|
LL | #[inline] struct S;
| ^^^^^^^^^
@ -81,7 +89,7 @@ LL | #[inline] struct S;
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:55:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:5
|
LL | #[inline] type T = S;
| ^^^^^^^^^
@ -89,15 +97,63 @@ LL | #[inline] type T = S;
= help: `#[inline]` can only be applied to functions
error: `#[inline]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:58:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:57:5
|
LL | #[inline] impl S { }
| ^^^^^^^^^
|
= help: `#[inline]` can only be applied to functions
error: `#[no_link]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:61:1
|
LL | #[no_link]
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:64:17
|
LL | mod inner { #![no_link] }
| ^^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on functions
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:5
|
LL | #[no_link] fn f() {
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:77:5
|
LL | #[no_link]
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:86:5
|
LL | #[no_link]type T = S;
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[no_link]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:89:5
|
LL | #[no_link] impl S { }
| ^^^^^^^^^^
|
= help: `#[no_link]` can only be applied to extern crates
error: `#[export_name]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:88:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:98:1
|
LL | #[export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -105,7 +161,7 @@ LL | #[export_name = "2200"]
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on modules
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:91:17
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:101:17
|
LL | mod inner { #![export_name="2200"] }
| ^^^^^^^^^^^^^^^^^^^^^^
@ -113,7 +169,7 @@ LL | mod inner { #![export_name="2200"] }
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on structs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:96:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:5
|
LL | #[export_name = "2200"] struct S;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -121,7 +177,7 @@ LL | #[export_name = "2200"] struct S;
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on type aliases
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:99:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109:5
|
LL | #[export_name = "2200"] type T = S;
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -129,7 +185,7 @@ LL | #[export_name = "2200"] type T = S;
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on inherent impl blocks
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:102:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:112:5
|
LL | #[export_name = "2200"] impl S { }
| ^^^^^^^^^^^^^^^^^^^^^^^
@ -137,29 +193,15 @@ LL | #[export_name = "2200"] impl S { }
= help: `#[export_name]` can be applied to functions and statics
error: `#[export_name]` attribute cannot be used on required trait methods
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:106:9
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:116:9
|
LL | #[export_name = "2200"] fn foo();
| ^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[export_name]` can be applied to functions, inherent methods, provided trait methods, statics, and trait methods in impl blocks
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:62:1
|
LL | #[no_link]
| ^^^^^^^^^^
LL |
LL | / mod no_link {
LL | |
LL | |
LL | | mod inner { #![no_link] }
... |
LL | | }
| |_- not an `extern crate` item
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113:8
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123:8
|
LL | #[repr(C)]
| ^
@ -172,7 +214,7 @@ LL | | }
| |_- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:8
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147:8
|
LL | #[repr(Rust)]
| ^^^^
@ -184,20 +226,14 @@ LL | | mod inner { #![repr(Rust)] }
LL | | }
| |_- not a struct, enum, or union
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:31:1
|
LL | #![no_link]
| ^^^^^^^^^^^ not an `extern crate` item
warning: `#[no_mangle]` attribute may not be used in combination with `#[export_name]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1
|
LL | #![no_mangle]
| ^^^^^^^^^^^^^ `#[no_mangle]` is ignored
|
note: `#[export_name]` takes precedence
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:33:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:32:1
|
LL | #![export_name = "2200"]
| ^^^^^^^^^^^^^^^^^^^^^^^^
@ -208,7 +244,7 @@ LL - #![no_mangle]
|
error: `repr` attribute cannot be used at crate level
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:17:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
|
LL | #![repr()]
| ^^^^^^^^^^
@ -222,86 +258,56 @@ LL - #![repr()]
LL + #[repr()]
|
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67:17
|
LL | mod inner { #![no_link] }
| ------------^^^^^^^^^^^-- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:71:5
|
LL | #[no_link] fn f() { }
| ^^^^^^^^^^ ---------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:75:5
|
LL | #[no_link] struct S;
| ^^^^^^^^^^ --------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:79:5
|
LL | #[no_link]type T = S;
| ^^^^^^^^^^----------- not an `extern crate` item
error: attribute should be applied to an `extern crate` item
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:83:5
|
LL | #[no_link] impl S { }
| ^^^^^^^^^^ ---------- not an `extern crate` item
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:117:25
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:25
|
LL | mod inner { #![repr(C)] }
| --------------------^---- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:121:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12
|
LL | #[repr(C)] fn f() { }
| ^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:127:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137:12
|
LL | #[repr(C)] type T = S;
| ^ ----------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:131:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:12
|
LL | #[repr(C)] impl S { }
| ^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:141:25
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:25
|
LL | mod inner { #![repr(Rust)] }
| --------------------^^^^---- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:145:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12
|
LL | #[repr(Rust)] fn f() { }
| ^^^^ ---------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:151:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:161:12
|
LL | #[repr(Rust)] type T = S;
| ^^^^ ----------- not a struct, enum, or union
error[E0517]: attribute should be applied to a struct, enum, or union
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:155:12
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:165:12
|
LL | #[repr(Rust)] impl S { }
| ^^^^ ---------- not a struct, enum, or union
error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5
|
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^
@ -310,8 +316,35 @@ LL | #[inline = "2100"] fn f() { }
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` (part of `#[deny(future_incompatible)]`) on by default
warning: `#[no_link]` attribute cannot be used on match arms
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:70:13
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: `#[no_link]` attribute cannot be used on struct fields
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:9
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: `#[no_link]` attribute cannot be used on macro defs
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:92:5
|
LL | #[no_link]
| ^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_link]` can only be applied to extern crates
warning: unused attribute
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:17:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:16:1
|
LL | #![repr()]
| ^^^^^^^^^^ help: remove this attribute
@ -319,7 +352,7 @@ LL | #![repr()]
= note: using `repr` with an empty list has no effect
warning: `#[no_mangle]` attribute cannot be used on crates
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:25:1
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:24:1
|
LL | #![no_mangle]
| ^^^^^^^^^^^^^
@ -327,13 +360,13 @@ LL | #![no_mangle]
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= help: `#[no_mangle]` can be applied to functions and statics
error: aborting due to 37 previous errors; 3 warnings emitted
error: aborting due to 37 previous errors; 6 warnings emitted
Some errors have detailed explanations: E0517, E0658.
For more information about an error, try `rustc --explain E0517`.
Future incompatibility report: Future breakage diagnostic:
error: valid forms for the attribute are `#[inline(always)]`, `#[inline(never)]`, and `#[inline]`
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:46:5
--> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:45:5
|
LL | #[inline = "2100"] fn f() { }
| ^^^^^^^^^^^^^^^^^^

View file

@ -9,20 +9,24 @@ fn foo2<const X: usize>() {}
#[rustc_legacy_const_generics(2)] //~ ERROR index exceeds number of arguments
fn foo3<const X: usize>(_: u8) {}
#[rustc_legacy_const_generics(a)] //~ ERROR arguments should be non-negative integers
#[rustc_legacy_const_generics(a)] //~ ERROR malformed `rustc_legacy_const_generics` attribute input
fn foo4<const X: usize>() {}
#[rustc_legacy_const_generics(1, a, 2, b)] //~ ERROR arguments should be non-negative integers
#[rustc_legacy_const_generics(1, a, 2, b)]
//~^ ERROR malformed `rustc_legacy_const_generics` attribute input
//~^^ ERROR malformed `rustc_legacy_const_generics` attribute input
fn foo5<const X: usize, const Y: usize, const Z: usize, const W: usize>() {}
#[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function
#[rustc_legacy_const_generics(0)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on structs
struct S;
#[rustc_legacy_const_generics(0usize)] //~ ERROR suffixed literals are not allowed in attributes
#[rustc_legacy_const_generics(0usize)]
//~^ ERROR suffixed literals are not allowed in attributes
//~^^ ERROR malformed `rustc_legacy_const_generics` attribute input
fn foo6<const X: usize>() {}
extern "C" {
#[rustc_legacy_const_generics(1)] //~ ERROR attribute should be applied to a function
#[rustc_legacy_const_generics(1)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on foreign functions
fn foo7<const X: usize>(); //~ ERROR foreign items may not have const parameters
}
@ -30,14 +34,14 @@ extern "C" {
fn foo8<X>() {}
impl S {
#[rustc_legacy_const_generics(0)] //~ ERROR attribute should be applied to a function
#[rustc_legacy_const_generics(0)] //~ ERROR `#[rustc_legacy_const_generics]` attribute cannot be used on inherent methods
fn foo9<const X: usize>() {}
}
#[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute
#[rustc_legacy_const_generics] //~ ERROR malformed `rustc_legacy_const_generics` attribute input
fn bar1() {}
#[rustc_legacy_const_generics = 1] //~ ERROR malformed `rustc_legacy_const_generics` attribute
#[rustc_legacy_const_generics = 1] //~ ERROR malformed `rustc_legacy_const_generics` attribute input
fn bar2() {}
fn main() {}

View file

@ -1,22 +1,88 @@
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:12:1
|
LL | #[rustc_legacy_const_generics(a)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| | |
| | expected an integer literal here
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:15:1
|
LL | #[rustc_legacy_const_generics(1, a, 2, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^^^^^^^
| | |
| | expected an integer literal here
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:15:1
|
LL | #[rustc_legacy_const_generics(1, a, 2, b)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-^^
| | |
| | expected an integer literal here
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error: `#[rustc_legacy_const_generics]` attribute cannot be used on structs
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:20:1
|
LL | #[rustc_legacy_const_generics(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
error: suffixed literals are not allowed in attributes
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:21:31
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:23:31
|
LL | #[rustc_legacy_const_generics(0usize)]
| ^^^^^^
|
= help: instead of using a suffixed literal (`1u8`, `1.0f32`, etc.), use an unsuffixed version (`1`, `1.0`, etc.)
error: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:1
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:23:1
|
LL | #[rustc_legacy_const_generics(0usize)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^------^^
| | |
| | expected an integer literal here
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error: `#[rustc_legacy_const_generics]` attribute cannot be used on foreign functions
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:29:5
|
LL | #[rustc_legacy_const_generics(1)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
error: `#[rustc_legacy_const_generics]` attribute cannot be used on inherent methods
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:37:5
|
LL | #[rustc_legacy_const_generics(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: `#[rustc_legacy_const_generics]` can only be applied to functions
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:41:1
|
LL | #[rustc_legacy_const_generics]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| expected this to be a list
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:40:1
error[E0539]: malformed `rustc_legacy_const_generics` attribute input
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:44:1
|
LL | #[rustc_legacy_const_generics = 1]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_legacy_const_generics(N)]`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^
| | |
| | expected this to be a list
| help: must be of the form: `#[rustc_legacy_const_generics(N)]`
error: #[rustc_legacy_const_generics] must have one index for each generic parameter
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:3:1
@ -38,58 +104,23 @@ error: index exceeds number of arguments
LL | #[rustc_legacy_const_generics(2)]
| ^ there are only 2 arguments
error: arguments should be non-negative integers
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:12:31
|
LL | #[rustc_legacy_const_generics(a)]
| ^
error: arguments should be non-negative integers
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:15:34
|
LL | #[rustc_legacy_const_generics(1, a, 2, b)]
| ^ ^
error: attribute should be applied to a function definition
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:18:1
|
LL | #[rustc_legacy_const_generics(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | struct S;
| --------- not a function definition
error: #[rustc_legacy_const_generics] functions must only have const generics
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:29:1
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:1
|
LL | #[rustc_legacy_const_generics(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn foo8<X>() {}
| - non-const generic parameter
error: attribute should be applied to a function definition
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:33:5
|
LL | #[rustc_legacy_const_generics(0)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn foo9<const X: usize>() {}
| ---------------------------- not a function definition
error: attribute should be applied to a function definition
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:25:5
|
LL | #[rustc_legacy_const_generics(1)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | fn foo7<const X: usize>();
| -------------------------- not a function definition
error[E0044]: foreign items may not have const parameters
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:26:5
--> $DIR/invalid-rustc_legacy_const_generics-arguments.rs:30:5
|
LL | fn foo7<const X: usize>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ can't have const parameters
|
= help: replace the const parameters with concrete consts
error: aborting due to 13 previous errors
error: aborting due to 15 previous errors
For more information about this error, try `rustc --explain E0044`.
Some errors have detailed explanations: E0044, E0539.
For more information about an error, try `rustc --explain E0044`.

View file

@ -16,18 +16,6 @@ note: the lint level is defined here
LL | #![deny(unused_attributes)]
| ^^^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:37:1
|
LL | #[no_link]
| ^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:36:1
|
LL | #[no_link]
| ^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:34:1
|
@ -40,6 +28,18 @@ note: attribute also specified here
LL | #![no_builtins]
| ^^^^^^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:37:1
|
LL | #[no_link]
| ^^^^^^^^^^ help: remove this attribute
|
note: attribute also specified here
--> $DIR/unused-attr-duplicate.rs:36:1
|
LL | #[no_link]
| ^^^^^^^^^^
error: unused attribute
--> $DIR/unused-attr-duplicate.rs:41:1
|