diff --git a/compiler/rustc_ast/src/entry.rs b/compiler/rustc_ast/src/entry.rs index 12cbb3b2a15f7..ae0cc7350a78f 100644 --- a/compiler/rustc_ast/src/entry.rs +++ b/compiler/rustc_ast/src/entry.rs @@ -1,7 +1,5 @@ use rustc_span::{Symbol, sym}; -use crate::attr::{self, AttributeExt}; - #[derive(Debug)] pub enum EntryPointType { /// This function is not an entrypoint. @@ -30,11 +28,11 @@ pub enum EntryPointType { } pub fn entry_point_type( - attrs: &[impl AttributeExt], + has_rustc_main: bool, at_root: bool, name: Option, ) -> EntryPointType { - if attr::contains_name(attrs, sym::rustc_main) { + if has_rustc_main { EntryPointType::RustcMainAttr } else if let Some(name) = name && name == sym::main diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index cf2f5c6c79024..455c61097d78d 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -1,9 +1,18 @@ use super::prelude::*; use super::util::parse_single_integer; -pub(crate) struct RustcLayoutScalarValidRangeStart; +pub(crate) struct RustcMainParser; -impl SingleAttributeParser for RustcLayoutScalarValidRangeStart { +impl NoArgsAttributeParser for RustcMainParser { + const PATH: &'static [Symbol] = &[sym::rustc_main]; + const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; + const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Fn)]); + const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcMain; +} + +pub(crate) struct RustcLayoutScalarValidRangeStartParser; + +impl SingleAttributeParser for RustcLayoutScalarValidRangeStartParser { const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_start]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; @@ -16,9 +25,9 @@ impl SingleAttributeParser for RustcLayoutScalarValidRangeStart { } } -pub(crate) struct RustcLayoutScalarValidRangeEnd; +pub(crate) struct RustcLayoutScalarValidRangeEndParser; -impl SingleAttributeParser for RustcLayoutScalarValidRangeEnd { +impl SingleAttributeParser for RustcLayoutScalarValidRangeEndParser { const PATH: &'static [Symbol] = &[sym::rustc_layout_scalar_valid_range_end]; const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepInnermost; const ON_DUPLICATE: OnDuplicate = OnDuplicate::Error; diff --git a/compiler/rustc_attr_parsing/src/context.rs b/compiler/rustc_attr_parsing/src/context.rs index e8bb4caa41664..6749bdfb1a672 100644 --- a/compiler/rustc_attr_parsing/src/context.rs +++ b/compiler/rustc_attr_parsing/src/context.rs @@ -53,7 +53,7 @@ use crate::attributes::proc_macro_attrs::{ use crate::attributes::prototype::CustomMirParser; use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser}; use crate::attributes::rustc_internal::{ - RustcLayoutScalarValidRangeEnd, RustcLayoutScalarValidRangeStart, + RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser, RustcMainParser, RustcObjectLifetimeDefaultParser, RustcSimdMonomorphizeLaneLimitParser, }; use crate::attributes::semantics::MayDangleParser; @@ -197,8 +197,8 @@ attribute_parsers!( Single, Single, Single, - Single, - Single, + Single, + Single, Single, Single, Single, @@ -238,6 +238,7 @@ attribute_parsers!( Single>, Single>, Single>, + Single>, Single>, Single>, Single>, diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 82c59d5a3a20b..2a6ac5754bfaf 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -3,6 +3,7 @@ use std::mem; use rustc_ast as ast; +use rustc_ast::attr::contains_name; use rustc_ast::entry::EntryPointType; use rustc_ast::mut_visit::*; use rustc_ast::visit::Visitor; @@ -172,9 +173,11 @@ impl<'a> Visitor<'a> for InnerItemLinter<'_> { fn entry_point_type(item: &ast::Item, at_root: bool) -> EntryPointType { match &item.kind { - ast::ItemKind::Fn(fn_) => { - rustc_ast::entry::entry_point_type(&item.attrs, at_root, Some(fn_.ident.name)) - } + ast::ItemKind::Fn(fn_) => rustc_ast::entry::entry_point_type( + contains_name(&item.attrs, sym::rustc_main), + at_root, + Some(fn_.ident.name), + ), _ => EntryPointType::None, } } diff --git a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs index e8c8729f597b9..44de48a3ada51 100644 --- a/compiler/rustc_codegen_ssa/src/codegen_attrs.rs +++ b/compiler/rustc_codegen_ssa/src/codegen_attrs.rs @@ -279,7 +279,7 @@ fn process_builtin_attrs( AttributeKind::StdInternalSymbol(_) => { codegen_fn_attrs.flags |= CodegenFnAttrFlags::RUSTC_STD_INTERNAL_SYMBOL } - AttributeKind::Linkage(linkage, _) => { + AttributeKind::Linkage(linkage, span) => { let linkage = Some(*linkage); if tcx.is_foreign_item(did) { @@ -287,7 +287,7 @@ fn process_builtin_attrs( if tcx.is_mutable_static(did.into()) { let mut diag = tcx.dcx().struct_span_err( - attr.span(), + *span, "extern mutable statics are not allowed with `#[linkage]`", ); diag.note( diff --git a/compiler/rustc_hir/src/attrs/data_structures.rs b/compiler/rustc_hir/src/attrs/data_structures.rs index 2435363ef0eb8..516e7cf604fd1 100644 --- a/compiler/rustc_hir/src/attrs/data_structures.rs +++ b/compiler/rustc_hir/src/attrs/data_structures.rs @@ -670,6 +670,9 @@ pub enum AttributeKind { /// Represents `#[rustc_layout_scalar_valid_range_start]`. RustcLayoutScalarValidRangeStart(Box, Span), + /// Represents `#[rustc_main]`. + RustcMain, + /// Represents `#[rustc_object_lifetime_default]`. RustcObjectLifetimeDefault, diff --git a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs index 1611b865c7726..362ab407aab35 100644 --- a/compiler/rustc_hir/src/attrs/encode_cross_crate.rs +++ b/compiler/rustc_hir/src/attrs/encode_cross_crate.rs @@ -88,6 +88,7 @@ impl AttributeKind { RustcCoherenceIsCore(..) => No, RustcLayoutScalarValidRangeEnd(..) => Yes, RustcLayoutScalarValidRangeStart(..) => Yes, + RustcMain => No, RustcObjectLifetimeDefault => No, RustcSimdMonomorphizeLaneLimit(..) => Yes, // Affects layout computation, which needs to work cross-crate Sanitize { .. } => No, diff --git a/compiler/rustc_hir/src/attrs/pretty_printing.rs b/compiler/rustc_hir/src/attrs/pretty_printing.rs index d13cd3fd1dab0..ea86dfbd9c80e 100644 --- a/compiler/rustc_hir/src/attrs/pretty_printing.rs +++ b/compiler/rustc_hir/src/attrs/pretty_printing.rs @@ -26,16 +26,6 @@ pub trait PrintAttribute { fn print_attribute(&self, p: &mut Printer); } -impl PrintAttribute for u128 { - fn should_render(&self) -> bool { - true - } - - fn print_attribute(&self, p: &mut Printer) { - p.word(self.to_string()) - } -} - impl PrintAttribute for &T { fn should_render(&self) -> bool { T::should_render(self) @@ -148,7 +138,7 @@ macro_rules! print_tup { print_tup!(A B C D E F G H); print_skip!(Span, (), ErrorGuaranteed); -print_disp!(u16, bool, NonZero, Limit); +print_disp!(u16, u128, bool, NonZero, Limit); print_debug!( Symbol, Ident, diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index bc1c47e95c3ae..2f60a9119cbe2 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -1315,8 +1315,6 @@ impl AttributeExt for Attribute { // FIXME: should not be needed anymore when all attrs are parsed Attribute::Parsed(AttributeKind::DocComment { span, .. }) => *span, Attribute::Parsed(AttributeKind::Deprecation { span, .. }) => *span, - Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span)) => *span, - Attribute::Parsed(AttributeKind::Linkage(_, span)) => *span, a => panic!("can't get the span of an arbitrary parsed attribute: {a:?}"), } } diff --git a/compiler/rustc_index/src/bit_set.rs b/compiler/rustc_index/src/bit_set.rs index d5a184c259319..2de892fa797ab 100644 --- a/compiler/rustc_index/src/bit_set.rs +++ b/compiler/rustc_index/src/bit_set.rs @@ -160,7 +160,7 @@ impl DenseBitSet { /// Count the number of set bits in the set. pub fn count(&self) -> usize { - self.words.iter().map(|e| e.count_ones() as usize).sum() + count_ones(&self.words) } /// Returns `true` if `self` contains `elem`. @@ -786,7 +786,7 @@ impl BitRelations> for ChunkedBitSet { match (&mut self_chunk, &other_chunk) { (_, Zeros) | (Ones, _) => {} - (Zeros, Ones) | (Mixed(..), Ones) | (Zeros, Mixed(..)) => { + (Zeros, _) | (Mixed(..), Ones) => { // `other_chunk` fully overwrites `self_chunk` *self_chunk = other_chunk.clone(); changed = true; @@ -814,10 +814,8 @@ impl BitRelations> for ChunkedBitSet { op, ); debug_assert!(has_changed); - *self_chunk_count = self_chunk_words[0..num_words] - .iter() - .map(|w| w.count_ones() as ChunkSize) - .sum(); + *self_chunk_count = + count_ones(&self_chunk_words[0..num_words]) as ChunkSize; if *self_chunk_count == chunk_domain_size { *self_chunk = Ones; } @@ -850,7 +848,7 @@ impl BitRelations> for ChunkedBitSet { match (&mut self_chunk, &other_chunk) { (Zeros, _) | (_, Zeros) => {} - (Ones | Mixed(_, _), Ones) => { + (Ones | Mixed(..), Ones) => { changed = true; *self_chunk = Zeros; } @@ -868,10 +866,7 @@ impl BitRelations> for ChunkedBitSet { let self_chunk_count = chunk_domain_size - *other_chunk_count; debug_assert_eq!( self_chunk_count, - self_chunk_words[0..num_words] - .iter() - .map(|w| w.count_ones() as ChunkSize) - .sum() + count_ones(&self_chunk_words[0..num_words]) as ChunkSize ); *self_chunk = Mixed(self_chunk_count, Rc::new(self_chunk_words)); } @@ -894,10 +889,8 @@ impl BitRelations> for ChunkedBitSet { op, ); debug_assert!(has_changed); - *self_chunk_count = self_chunk_words[0..num_words] - .iter() - .map(|w| w.count_ones() as ChunkSize) - .sum(); + *self_chunk_count = + count_ones(&self_chunk_words[0..num_words]) as ChunkSize; if *self_chunk_count == 0 { *self_chunk = Zeros; } @@ -953,10 +946,8 @@ impl BitRelations> for ChunkedBitSet { op, ); debug_assert!(has_changed); - *self_chunk_count = self_chunk_words[0..num_words] - .iter() - .map(|w| w.count_ones() as ChunkSize) - .sum(); + *self_chunk_count = + count_ones(&self_chunk_words[0..num_words]) as ChunkSize; if *self_chunk_count == 0 { *self_chunk = Zeros; } @@ -970,48 +961,6 @@ impl BitRelations> for ChunkedBitSet { } } -impl BitRelations> for DenseBitSet { - fn union(&mut self, other: &ChunkedBitSet) -> bool { - sequential_update(|elem| self.insert(elem), other.iter()) - } - - fn subtract(&mut self, _other: &ChunkedBitSet) -> bool { - unimplemented!("implement if/when necessary"); - } - - fn intersect(&mut self, other: &ChunkedBitSet) -> bool { - assert_eq!(self.domain_size(), other.domain_size); - let mut changed = false; - for (i, chunk) in other.chunks.iter().enumerate() { - let mut words = &mut self.words[i * CHUNK_WORDS..]; - if words.len() > CHUNK_WORDS { - words = &mut words[..CHUNK_WORDS]; - } - match chunk { - Zeros => { - for word in words { - if *word != 0 { - changed = true; - *word = 0; - } - } - } - Ones => (), - Mixed(_, data) => { - for (i, word) in words.iter_mut().enumerate() { - let new_val = *word & data[i]; - if new_val != *word { - changed = true; - *word = new_val; - } - } - } - } - } - changed - } -} - impl Clone for ChunkedBitSet { fn clone(&self) -> Self { ChunkedBitSet { @@ -1085,21 +1034,12 @@ impl Chunk { assert!(0 < count && count < chunk_domain_size); // Check the number of set bits matches `count`. - assert_eq!( - words.iter().map(|w| w.count_ones() as ChunkSize).sum::(), - count - ); + assert_eq!(count_ones(words.as_slice()) as ChunkSize, count); // Check the not-in-use words are all zeroed. let num_words = num_words(chunk_domain_size as usize); if num_words < CHUNK_WORDS { - assert_eq!( - words[num_words..] - .iter() - .map(|w| w.count_ones() as ChunkSize) - .sum::(), - 0 - ); + assert_eq!(count_ones(&words[num_words..]) as ChunkSize, 0); } } } @@ -1122,15 +1062,6 @@ enum ChunkIter<'a> { Finished, } -// Applies a function to mutate a bitset, and returns true if any -// of the applications return true -fn sequential_update( - mut self_update: impl FnMut(T) -> bool, - it: impl Iterator, -) -> bool { - it.fold(false, |changed, elem| self_update(elem) | changed) -} - impl fmt::Debug for ChunkedBitSet { fn fmt(&self, w: &mut fmt::Formatter<'_>) -> fmt::Result { w.debug_list().entries(self.iter()).finish() @@ -1590,7 +1521,7 @@ impl BitMatrix { /// Returns the number of elements in `row`. pub fn count(&self, row: R) -> usize { let (start, end) = self.range(row); - self.words[start..end].iter().map(|e| e.count_ones() as usize).sum() + count_ones(&self.words[start..end]) } } @@ -1801,6 +1732,11 @@ fn max_bit(word: Word) -> usize { WORD_BITS - 1 - word.leading_zeros() as usize } +#[inline] +fn count_ones(words: &[Word]) -> usize { + words.iter().map(|word| word.count_ones() as usize).sum() +} + /// Integral type used to represent the bit set. pub trait FiniteBitSetTy: BitAnd diff --git a/compiler/rustc_index/src/bit_set/tests.rs b/compiler/rustc_index/src/bit_set/tests.rs index deddc87261436..341e0622df75e 100644 --- a/compiler/rustc_index/src/bit_set/tests.rs +++ b/compiler/rustc_index/src/bit_set/tests.rs @@ -306,34 +306,6 @@ fn with_elements_chunked(elements: &[usize], domain_size: usize) -> ChunkedBitSe s } -fn with_elements_standard(elements: &[usize], domain_size: usize) -> DenseBitSet { - let mut s = DenseBitSet::new_empty(domain_size); - for &e in elements { - assert!(s.insert(e)); - } - s -} - -#[test] -fn chunked_bitset_into_bitset_operations() { - let a = vec![1, 5, 7, 11, 15, 2000, 3000]; - let b = vec![3, 4, 11, 3000, 4000]; - let aub = vec![1, 3, 4, 5, 7, 11, 15, 2000, 3000, 4000]; - let aib = vec![11, 3000]; - - let b = with_elements_chunked(&b, 9876); - - let mut union = with_elements_standard(&a, 9876); - assert!(union.union(&b)); - assert!(!union.union(&b)); - assert!(union.iter().eq(aub.iter().copied())); - - let mut intersection = with_elements_standard(&a, 9876); - assert!(intersection.intersect(&b)); - assert!(!intersection.intersect(&b)); - assert!(intersection.iter().eq(aib.iter().copied())); -} - #[test] fn chunked_bitset_iter() { fn check_iter(bit: &ChunkedBitSet, vec: &Vec) { diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 8a525eb11f7bb..d14bc600f2f11 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -310,15 +310,17 @@ impl EarlyLintPass for UnsafeCode { } ast::ItemKind::MacroDef(..) => { - if let Some(attr) = AttributeParser::parse_limited( - cx.builder.sess(), - &it.attrs, - sym::allow_internal_unsafe, - it.span, - DUMMY_NODE_ID, - Some(cx.builder.features()), - ) { - self.report_unsafe(cx, attr.span(), BuiltinUnsafe::AllowInternalUnsafe); + if let Some(hir::Attribute::Parsed(AttributeKind::AllowInternalUnsafe(span))) = + AttributeParser::parse_limited( + cx.builder.sess(), + &it.attrs, + sym::allow_internal_unsafe, + it.span, + DUMMY_NODE_ID, + Some(cx.builder.features()), + ) + { + self.report_unsafe(cx, span, BuiltinUnsafe::AllowInternalUnsafe); } } diff --git a/compiler/rustc_passes/messages.ftl b/compiler/rustc_passes/messages.ftl index dc956b9f3169b..c668bf0733d14 100644 --- a/compiler/rustc_passes/messages.ftl +++ b/compiler/rustc_passes/messages.ftl @@ -34,9 +34,6 @@ passes_attr_crate_level = .suggestion = to apply to the crate, use an inner attribute .note = read for more information -passes_attr_only_in_functions = - `{$attr}` attribute can only be used on functions - passes_autodiff_attr = `#[autodiff]` should be applied to a function .label = not a function diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index c4ceba0840f13..4c4f3470e3452 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -283,6 +283,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> { | AttributeKind::ObjcSelector { .. } | AttributeKind::RustcCoherenceIsCore(..) | AttributeKind::DebuggerVisualizer(..) + | AttributeKind::RustcMain, ) => { /* do nothing */ } Attribute::Unparsed(attr_item) => { style = Some(attr_item.style); @@ -2397,14 +2398,8 @@ fn check_invalid_crate_level_attr(tcx: TyCtxt<'_>, attrs: &[Attribute]) { // Check for builtin attributes at the crate level // which were unsuccessfully resolved due to cannot determine // resolution for the attribute macro error. - const ATTRS_TO_CHECK: &[Symbol] = &[ - sym::rustc_main, - sym::derive, - sym::test, - sym::test_case, - sym::global_allocator, - sym::bench, - ]; + const ATTRS_TO_CHECK: &[Symbol] = + &[sym::derive, sym::test, sym::test_case, sym::global_allocator, sym::bench]; for attr in attrs { // FIXME(jdonszelmann): all attrs should be combined here cleaning this up some day. diff --git a/compiler/rustc_passes/src/entry.rs b/compiler/rustc_passes/src/entry.rs index 2a435c4b2e05c..8ed2c2a892660 100644 --- a/compiler/rustc_passes/src/entry.rs +++ b/compiler/rustc_passes/src/entry.rs @@ -1,16 +1,16 @@ use rustc_ast::attr; use rustc_ast::entry::EntryPointType; use rustc_errors::codes::*; -use rustc_hir::def::DefKind; +use rustc_hir::attrs::AttributeKind; use rustc_hir::def_id::{CRATE_DEF_ID, DefId, LOCAL_CRATE, LocalDefId}; -use rustc_hir::{CRATE_HIR_ID, ItemId, Node}; +use rustc_hir::{CRATE_HIR_ID, ItemId, Node, find_attr}; use rustc_middle::query::Providers; use rustc_middle::ty::TyCtxt; use rustc_session::RemapFileNameExt; use rustc_session::config::{CrateType, EntryFnType, RemapPathScopeComponents, sigpipe}; -use rustc_span::{Span, Symbol, sym}; +use rustc_span::{Span, sym}; -use crate::errors::{AttrOnlyInFunctions, ExternMain, MultipleRustcMain, NoMainErr}; +use crate::errors::{ExternMain, MultipleRustcMain, NoMainErr}; struct EntryContext<'tcx> { tcx: TyCtxt<'tcx>, @@ -44,26 +44,12 @@ fn entry_fn(tcx: TyCtxt<'_>, (): ()) -> Option<(DefId, EntryFnType)> { configure_main(tcx, &ctxt) } -fn attr_span_by_symbol(ctxt: &EntryContext<'_>, id: ItemId, sym: Symbol) -> Option { - let attrs = ctxt.tcx.hir_attrs(id.hir_id()); - attr::find_by_name(attrs, sym).map(|attr| attr.span()) -} - fn check_and_search_item(id: ItemId, ctxt: &mut EntryContext<'_>) { - if !matches!(ctxt.tcx.def_kind(id.owner_id), DefKind::Fn) { - for attr in [sym::rustc_main] { - if let Some(span) = attr_span_by_symbol(ctxt, id, attr) { - ctxt.tcx.dcx().emit_err(AttrOnlyInFunctions { span, attr }); - } - } - return; - } - let at_root = ctxt.tcx.opt_local_parent(id.owner_id.def_id) == Some(CRATE_DEF_ID); let attrs = ctxt.tcx.hir_attrs(id.hir_id()); let entry_point_type = rustc_ast::entry::entry_point_type( - attrs, + find_attr!(attrs, AttributeKind::RustcMain), at_root, ctxt.tcx.opt_item_name(id.owner_id.to_def_id()), ); diff --git a/compiler/rustc_passes/src/errors.rs b/compiler/rustc_passes/src/errors.rs index 7d184d8bb694c..f5023646b1917 100644 --- a/compiler/rustc_passes/src/errors.rs +++ b/compiler/rustc_passes/src/errors.rs @@ -843,14 +843,6 @@ pub(crate) struct FeaturePreviouslyDeclared<'a> { pub prev_declared: &'a str, } -#[derive(Diagnostic)] -#[diag(passes_attr_only_in_functions)] -pub(crate) struct AttrOnlyInFunctions { - #[primary_span] - pub span: Span, - pub attr: Symbol, -} - #[derive(Diagnostic)] #[diag(passes_multiple_rustc_main, code = E0137)] pub(crate) struct MultipleRustcMain { diff --git a/compiler/rustc_target/src/callconv/bpf.rs b/compiler/rustc_target/src/callconv/bpf.rs index f958aeb9bb654..ec5c1c2cf6860 100644 --- a/compiler/rustc_target/src/callconv/bpf.rs +++ b/compiler/rustc_target/src/callconv/bpf.rs @@ -29,3 +29,9 @@ pub(crate) fn compute_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { classify_arg(arg); } } + +pub(crate) fn compute_rust_abi_info(fn_abi: &mut FnAbi<'_, Ty>) { + if !fn_abi.ret.is_ignore() { + classify_ret(&mut fn_abi.ret); + } +} diff --git a/compiler/rustc_target/src/callconv/mod.rs b/compiler/rustc_target/src/callconv/mod.rs index c59af581a1fe4..3f7382ee0e2b5 100644 --- a/compiler/rustc_target/src/callconv/mod.rs +++ b/compiler/rustc_target/src/callconv/mod.rs @@ -715,6 +715,7 @@ impl<'a, Ty> FnAbi<'a, Ty> { "riscv32" | "riscv64" => riscv::compute_rust_abi_info(cx, self), "loongarch32" | "loongarch64" => loongarch::compute_rust_abi_info(cx, self), "aarch64" => aarch64::compute_rust_abi_info(cx, self), + "bpf" => bpf::compute_rust_abi_info(self), _ => {} }; diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 46eb120d65de3..60c8f53a0cc40 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -65,7 +65,7 @@ //! So for example there is a [page for the primitive type //! `char`](primitive::char) that lists all the methods that can be called on //! characters (very useful), and there is a [page for the module -//! `std::char`] that documents iterator and error types created by these methods +//! `std::char`](crate::char) that documents iterator and error types created by these methods //! (rarely useful). //! //! Note the documentation for the primitives [`str`] and [`[T]`][prim@slice] (also @@ -180,9 +180,6 @@ //! //! //! [I/O]: io -//! [`MIN`]: i32::MIN -//! [`MAX`]: i32::MAX -//! [page for the module `std::i32`]: crate::i32 //! [TCP]: net::TcpStream //! [The Rust Prelude]: prelude //! [UDP]: net::UdpSocket diff --git a/tests/codegen-llvm/bpf-abi-indirect-return.rs b/tests/codegen-llvm/bpf-abi-indirect-return.rs new file mode 100644 index 0000000000000..b5787cc83a2b4 --- /dev/null +++ b/tests/codegen-llvm/bpf-abi-indirect-return.rs @@ -0,0 +1,43 @@ +// Checks that results larger than one register are returned indirectly +//@ only-bpf +//@ needs-llvm-components: bpf +//@ compile-flags: --target bpfel-unknown-none + +#![no_std] +#![no_main] + +#[no_mangle] +fn outer(a: u64) -> u64 { + let v = match inner_res(a) { + Ok(v) => v, + Err(()) => 0, + }; + + inner_big(v).a[0] as u64 +} + +// CHECK-LABEL: define {{.*}} @_ZN{{.*}}inner_res{{.*}}E( +// CHECK-SAME: ptr{{[^,]*}}, +// CHECK-SAME: i64{{[^)]*}} +#[inline(never)] +fn inner_res(a: u64) -> Result { + if a == 0 { Err(()) } else { Ok(a + 1) } +} + +struct Big { + a: [u16; 32], + b: u64, +} + +// CHECK-LABEL: define {{.*}} @_ZN{{.*}}inner_big{{.*}}E( +// CHECK-SAME: ptr{{[^,]*}}, +// CHECK-SAME: i64{{[^)]*}} +#[inline(never)] +fn inner_big(a: u64) -> Big { + Big { a: [a as u16; 32], b: 42 } +} + +#[panic_handler] +fn panic(_info: &core::panic::PanicInfo) -> ! { + loop {} +} diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs index a1a78df8d5375..4bea4487f16ae 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.rs @@ -10,7 +10,7 @@ #![macro_export] //~^ ERROR: `#[macro_export]` attribute cannot be used on crates #![rustc_main] -//~^ ERROR: `rustc_main` attribute cannot be used at crate level +//~^ ERROR: `#[rustc_main]` attribute cannot be used on crates //~| ERROR: use of an internal attribute [E0658] //~| NOTE: the `#[rustc_main]` attribute is an internal implementation detail that will never be stable //~| NOTE: the `#[rustc_main]` attribute is used internally to specify test entry point function @@ -31,7 +31,6 @@ //~^ ERROR attribute cannot be used on mod inline { //~^ NOTE the inner attribute doesn't annotate this module - //~| NOTE the inner attribute doesn't annotate this module mod inner { #![inline] } //~^ ERROR attribute cannot be used on diff --git a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr index 13152ca12e4b8..8091b0b28e624 100644 --- a/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr +++ b/tests/ui/feature-gates/issue-43106-gating-of-builtin-attrs-error.stderr @@ -16,6 +16,14 @@ 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 + | +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:19:1 | @@ -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:36:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:35:17 | LL | mod inner { #![inline] } | ^^^^^^^^^^ @@ -65,7 +73,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:45:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:44:5 | LL | #[inline] struct S; | ^^^^^^^^^ @@ -73,7 +81,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:48:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:47:5 | LL | #[inline] type T = S; | ^^^^^^^^^ @@ -81,7 +89,7 @@ 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:51:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:50:5 | LL | #[inline] impl S { } | ^^^^^^^^^ @@ -89,7 +97,7 @@ LL | #[inline] impl S { } = help: `#[inline]` can only be applied to functions error: `#[export_name]` attribute cannot be used on modules - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:81:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:80:1 | LL | #[export_name = "2200"] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -97,7 +105,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:84:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:83:17 | LL | mod inner { #![export_name="2200"] } | ^^^^^^^^^^^^^^^^^^^^^^ @@ -105,7 +113,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:89:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:88:5 | LL | #[export_name = "2200"] struct S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -113,7 +121,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:92:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:91:5 | LL | #[export_name = "2200"] type T = S; | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -121,7 +129,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:95:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:94:5 | LL | #[export_name = "2200"] impl S { } | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -129,7 +137,7 @@ 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:99:9 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:98:9 | LL | #[export_name = "2200"] fn foo(); | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -137,7 +145,7 @@ 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:55:1 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:54:1 | LL | #[no_link] | ^^^^^^^^^^ @@ -151,7 +159,7 @@ 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:106:8 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:105:8 | LL | #[repr(C)] | ^ @@ -164,7 +172,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:130:8 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:129:8 | LL | #[repr(Rust)] | ^^^^ @@ -182,21 +190,6 @@ error: attribute should be applied to an `extern crate` item LL | #![no_link] | ^^^^^^^^^^^ not an `extern crate` item -error: `rustc_main` attribute cannot be used at crate level - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:12:1 - | -LL | #![rustc_main] - | ^^^^^^^^^^^^^^ -... -LL | mod inline { - | ------ the inner attribute doesn't annotate this module - | -help: perhaps you meant to use an outer attribute - | -LL - #![rustc_main] -LL + #[rustc_main] - | - error: `repr` attribute cannot be used at crate level --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:17:1 | @@ -213,85 +206,85 @@ LL + #[repr()] | error: attribute should be applied to an `extern crate` item - --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:60:17 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:59: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:64:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:63: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:68:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:67: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:72:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:71: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:76:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:75: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:110:25 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:109: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:114:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:113: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:120:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:119: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:124:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:123: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:134:25 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:133: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:138:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:137: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:144:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:143: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:148:12 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:147: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:39:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:38:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^ @@ -306,7 +299,7 @@ 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:39:5 + --> $DIR/issue-43106-gating-of-builtin-attrs-error.rs:38:5 | LL | #[inline = "2100"] fn f() { } | ^^^^^^^^^^^^^^^^^^