Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8804eed
Propagate async closure output into its body
Dnreikronos Aug 24, 2026
1b7d358
Update async closure suggestion expectations
Dnreikronos Aug 24, 2026
c3b4701
Check type alignment is <= type size in data layout parser
beetrees Oct 28, 2026
baff3dc
Remove `i1_align` and `i8_align`
beetrees Oct 28, 2026
0e5af61
Refactor `rustc_show_spans` attribute to easily support more AST frag…
FranciscoTGouveia Nov 12, 2026
031b8b4
Support showing generic arguments in the `rustc_show_spans` attribute
FranciscoTGouveia Nov 12, 2026
c743290
rustc: avoid path dependent queries in source presence checks
yawnbo Nov 16, 2026
c66f091
Prune un/under used methods of `ast::Attribute`
mejrs Nov 13, 2026
18e604a
Combine the spans of generic arguments without dropping the `Token::R…
FranciscoTGouveia Nov 12, 2026
b1b5475
Implement `rustc_intrinsic(llvm = "...")`
veluca93 Oct 27, 2026
ef0369b
Move doc attribute and doc comment target checking to attribute parsing
JonathanBrouwer Nov 17, 2026
5543825
std: Enable `is_mips*_feature_detected` for MIPS release 6
tgross35 Oct 26, 2026
78c5cdd
std: Combine `is_mips64_feature_detected` into `is_mips_feature_detec…
tgross35 Oct 26, 2026
c22b6bf
Rollup merge of #164544 - veluca93:rustc_llvm_intrinsic, r=tgross35
JonathanBrouwer Nov 17, 2026
92b18a5
Rollup merge of #165007 - tgross35:mips-feature, r=aapoalas
JonathanBrouwer Nov 17, 2026
01791e2
Rollup merge of #165090 - beetrees:data-layout-check-align, r=bjorn3
JonathanBrouwer Nov 17, 2026
c581f86
Rollup merge of #165875 - FranciscoTGouveia:rustc-show-spans-attr, r=…
JonathanBrouwer Nov 17, 2026
6fa9268
Rollup merge of #166074 - yawnbo:main, r=petrochenkov
JonathanBrouwer Nov 17, 2026
746a18f
Rollup merge of #161708 - Dnreikronos:hir_typeck/async_closure_output…
JonathanBrouwer Nov 17, 2026
42959c5
Rollup merge of #165893 - mejrs:prune_ast_attribute, r=JonathanBrouwer
JonathanBrouwer Nov 17, 2026
7c5c8d8
Rollup merge of #166093 - JonathanBrouwer:doc-target, r=GuillaumeGomez
JonathanBrouwer Nov 17, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3924,6 +3924,7 @@ dependencies = [
name = "rustc_crate_store"
version = "0.0.0"
dependencies = [
"bitflags",
"rustc_abi",
"rustc_attr_ir",
"rustc_data_structures",
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_abi/src/callconv/reg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ impl Reg {
let dl = cx.data_layout();
match self.kind {
RegKind::Integer => match self.size.bits() {
1 => dl.i1_align,
2..=8 => dl.i8_align,
1..=8 => Align::ONE,
9..=16 => dl.i16_align,
17..=32 => dl.i32_align,
33..=64 => dl.i64_align,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_abi/src/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
Some(present_first) => present_first,
// Uninhabited because it has no variants, or only absent ones.
None if is_enum => {
return Ok(LayoutData::never_type(&self.cx));
return Ok(LayoutData::never_type());
}
// If it's a struct, still compute a layout so that we can still compute the
// field offsets.
Expand Down Expand Up @@ -412,7 +412,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
F: Deref<Target = &'a LayoutData<FieldIdx, VariantIdx>> + fmt::Debug + Copy,
{
let dl = self.cx.data_layout();
let mut align = if repr.pack.is_some() { dl.i8_align } else { dl.aggregate_align };
let mut align = if repr.pack.is_some() { Align::ONE } else { dl.aggregate_align };
let mut max_repr_align = repr.align;

// If all the non-ZST fields have the same repr and union repr optimizations aren't
Expand Down Expand Up @@ -601,7 +601,7 @@ impl<Cx: HasDataLayout> LayoutCalculator<Cx> {
{
let dl = self.cx.data_layout();
let pack = repr.pack;
let mut align = if pack.is_some() { dl.i8_align } else { dl.aggregate_align };
let mut align = if pack.is_some() { Align::ONE } else { dl.aggregate_align };
let mut max_repr_align = repr.align;
let mut in_memory_order: IndexVec<u32, FieldIdx> = fields.indices().collect();
let optimize_field_order = !repr.inhibit_struct_field_reordering();
Expand Down
24 changes: 11 additions & 13 deletions compiler/rustc_abi/src/layout/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ use rustc_hashes::Hash64;
use rustc_index::{Idx, IndexVec};

use crate::{
BackendRepr, FieldsShape, HasDataLayout, LayoutData, Niche, Primitive, Scalar, Size, Variants,
Align, BackendRepr, FieldsShape, HasDataLayout, LayoutData, Niche, Primitive, Scalar, Size,
Variants,
};

/// "Simple" layout constructors that cannot fail.
impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
pub fn unit<C: HasDataLayout>(cx: &C, sized: bool) -> Self {
let dl = cx.data_layout();
pub fn unit(sized: bool) -> Self {
LayoutData {
variants: Variants::Single { index: VariantIdx::new(0) },
fields: FieldsShape::Arbitrary {
Expand All @@ -20,28 +20,27 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
backend_repr: BackendRepr::Memory { sized },
largest_niche: None,
uninhabited: false,
align: dl.i8_align,
align: Align::ONE,
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align,
unadjusted_abi_align: Align::ONE,
repr_c: false,
randomization_seed: Hash64::new(0),
}
}

pub fn never_type<C: HasDataLayout>(cx: &C) -> Self {
let dl = cx.data_layout();
pub fn never_type() -> Self {
// This is also used for uninhabited enums, so we use `Variants::Empty`.
LayoutData {
variants: Variants::Empty,
fields: FieldsShape::Primitive,
backend_repr: BackendRepr::Memory { sized: true },
largest_niche: None,
uninhabited: true,
align: dl.i8_align,
align: Align::ONE,
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align,
unadjusted_abi_align: Align::ONE,
repr_c: false,
randomization_seed: Hash64::ZERO,
}
Expand Down Expand Up @@ -128,8 +127,7 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
///
/// Uninhabited variants get pruned as part of the layout calculation,
/// so this can be used after the fact to reconstitute a layout.
pub fn uninhabited_variant<C: HasDataLayout>(cx: &C, index: VariantIdx, fields: usize) -> Self {
let dl = cx.data_layout();
pub fn uninhabited_variant(index: VariantIdx, fields: usize) -> Self {
LayoutData {
variants: Variants::Single { index },
fields: match NonZero::new(fields) {
Expand All @@ -142,10 +140,10 @@ impl<FieldIdx: Idx, VariantIdx: Idx> LayoutData<FieldIdx, VariantIdx> {
backend_repr: BackendRepr::Memory { sized: true },
largest_niche: None,
uninhabited: true,
align: dl.i8_align,
align: Align::ONE,
size: Size::ZERO,
max_repr_align: None,
unadjusted_abi_align: dl.i8_align,
unadjusted_abi_align: Align::ONE,
repr_c: false,
// Variant layouts never flow back into actual layout computations,
// so dummy values are fine here.
Expand Down
53 changes: 30 additions & 23 deletions compiler/rustc_abi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,6 @@ pub struct PointerSpec {
#[derive(Debug, PartialEq, Eq)]
pub struct TargetDataLayout {
pub endian: Endian,
pub i1_align: Align,
pub i8_align: Align,
pub i16_align: Align,
pub i32_align: Align,
pub i64_align: Align,
Expand Down Expand Up @@ -359,8 +357,6 @@ impl Default for TargetDataLayout {
let align = |bits| Align::from_bits(bits).unwrap();
TargetDataLayout {
endian: Endian::Big,
i1_align: align(8),
i8_align: align(8),
i16_align: align(16),
i32_align: align(32),
i64_align: align(32),
Expand Down Expand Up @@ -394,6 +390,7 @@ pub enum TargetDataLayoutError<'a> {
InvalidBits { kind: &'a str, bit: &'a str, cause: &'a str, err: ParseIntError },
MissingAlignment { cause: &'a str },
InvalidAlignment { cause: &'a str, err: AlignFromBytesError },
AlignmentTooLargeForType { cause: &'a str, align: Align },
InconsistentTargetArchitecture { dl: &'a str, target: &'a str },
InconsistentTargetPointerWidth { pointer_size: u64, target: u16 },
InvalidBitsSize { err: String },
Expand Down Expand Up @@ -426,6 +423,9 @@ impl Diagnostic<'_> for TargetDataLayoutError<'_> {
.with_arg("cause", cause)
.with_arg("err", err.to_string())
}
TargetDataLayoutError::AlignmentTooLargeForType { cause, align } => {
Diag::new(dcx, level, msg!("alignment of `{$align}` bytes in \"data-layout\" is too large for `{$cause}`")).with_arg("align", align.bytes()).with_arg("cause", cause)
}
TargetDataLayoutError::InconsistentTargetArchitecture { dl, target } => {
Diag::new(dcx, level, msg!("inconsistent target specification: \"data-layout\" claims architecture is {$dl}-endian, while \"target-endian\" is `{$target}`"))
.with_arg("dl", dl).with_arg("target", target)
Expand Down Expand Up @@ -477,22 +477,28 @@ impl TargetDataLayout {
|s: &'a str, cause: &'a str| parse_bits(s, "size", cause).map(Size::from_bits);

// Parse an alignment string.
let parse_align_str = |s: &'a str, cause: &'a str| {
let parse_align_str = |s: &'a str, cause: &'a str, size_bits: u64| {
let align_from_bits = |bits| {
Align::from_bits(bits)
.map_err(|err| TargetDataLayoutError::InvalidAlignment { cause, err })
};
let abi = parse_bits(s, "alignment", cause)?;
Ok(align_from_bits(abi)?)
let align_bits = parse_bits(s, "alignment", cause)?;
let align = align_from_bits(align_bits)?;
let max_align_bytes = size_bits.div_ceil(8).next_power_of_two();
if align.bytes() > max_align_bytes {
Err(TargetDataLayoutError::AlignmentTooLargeForType { cause, align })
} else {
Ok(align)
}
};

// Parse an alignment sequence, possibly in the form `<align>[:<preferred_alignment>]`,
// ignoring the secondary alignment specifications.
let parse_align_seq = |s: &[&'a str], cause: &'a str| {
let parse_align_seq = |s: &[&'a str], cause: &'a str, size_bits: u64| {
if s.is_empty() {
return Err(TargetDataLayoutError::MissingAlignment { cause });
}
parse_align_str(s[0], cause)
parse_align_str(s[0], cause, size_bits)
};

let mut dl = TargetDataLayout::default();
Expand All @@ -508,12 +514,12 @@ impl TargetDataLayout {
[p] if p.starts_with('P') => {
dl.instruction_address_space = parse_address_space(&p[1..], "P")?
}
["a", a @ ..] => dl.aggregate_align = parse_align_seq(a, "a")?,
["f16", a @ ..] => dl.f16_align = parse_align_seq(a, "f16")?,
["f32", a @ ..] => dl.f32_align = parse_align_seq(a, "f32")?,
["f64", a @ ..] => dl.f64_align = parse_align_seq(a, "f64")?,
["f80", a @ ..] => dl.x87_f80_align = parse_align_seq(a, "f80")?,
["f128", a @ ..] => dl.f128_align = parse_align_seq(a, "f128")?,
["a", a @ ..] => dl.aggregate_align = parse_align_seq(a, "a", u64::MAX)?,
["f16", a @ ..] => dl.f16_align = parse_align_seq(a, "f16", 16)?,
["f32", a @ ..] => dl.f32_align = parse_align_seq(a, "f32", 32)?,
["f64", a @ ..] => dl.f64_align = parse_align_seq(a, "f64", 64)?,
["f80", a @ ..] => dl.x87_f80_align = parse_align_seq(a, "f80", 80)?,
["f128", a @ ..] => dl.f128_align = parse_align_seq(a, "f128", 128)?,
[p, s, a @ ..] if p.starts_with("p") => {
let mut p = p.strip_prefix('p').unwrap();
let mut _is_fat = false;
Expand Down Expand Up @@ -541,7 +547,7 @@ impl TargetDataLayout {
};

let pointer_size = parse_size(s, "p-")?;
let pointer_align = parse_align_seq(a, "p-")?;
let pointer_align = parse_align_seq(a, "p-", pointer_size.bits())?;
let info = PointerSpec {
pointer_offset: pointer_size,
pointer_size,
Expand Down Expand Up @@ -585,9 +591,10 @@ impl TargetDataLayout {
AddressSpace::ZERO
};

let pointer_size = parse_size(s, "p-")?;
let info = PointerSpec {
pointer_size: parse_size(s, "p-")?,
pointer_align: parse_align_str(a, "p-")?,
pointer_size,
pointer_align: parse_align_str(a, "p-", pointer_size.bits())?,
pointer_offset: parse_size(i, "p-")?,
_is_fat,
};
Expand All @@ -609,10 +616,10 @@ impl TargetDataLayout {
parse_size(&s[1..], "i")?; // For the user error.
continue;
};
let a = parse_align_seq(a, s)?;
let a = parse_align_seq(a, s, bits)?;
match bits {
1 => dl.i1_align = a,
8 => dl.i8_align = a,
// i1 and i8 always have an alignment of 1 byte - this has already been
// checked by `parse_align_seq` above.
16 => dl.i16_align = a,
32 => dl.i32_align = a,
64 => dl.i64_align = a,
Expand All @@ -627,7 +634,7 @@ impl TargetDataLayout {
}
[s, a @ ..] if s.starts_with('v') => {
let v_size = parse_size(&s[1..], "v")?;
let a = parse_align_seq(a, s)?;
let a = parse_align_seq(a, s, v_size.bits())?;
if let Some(v) = dl.vector_align.iter_mut().find(|v| v.0 == v_size) {
v.1 = a;
continue;
Expand Down Expand Up @@ -1280,7 +1287,7 @@ impl Integer {
let dl = cx.data_layout();

match self {
I8 => dl.i8_align,
I8 => Align::ONE,
I16 => dl.i16_align,
I32 => dl.i32_align,
I64 => dl.i64_align,
Expand Down
13 changes: 1 addition & 12 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ impl From<ParenthesizedArgs> for Box<GenericArgs> {
pub struct ParenthesizedArgs {
/// ```text
/// Foo(A, B) -> C
/// ^^^^^^^^^^^^^^
/// ^^^^^^^^^^^
/// ```
pub span: Span,

Expand Down Expand Up @@ -3556,17 +3556,6 @@ impl GeneratedAttr {
}
}

pub fn is_word(&self) -> bool {
match self {
GeneratedAttr::AutomaticallyDerived => true,
GeneratedAttr::RustcConstUnstableDerived => false,
GeneratedAttr::Inline => true,
GeneratedAttr::DocHidden => false,
GeneratedAttr::CoverageOff => false,
GeneratedAttr::RustcTestMarker(_) => false,
GeneratedAttr::RustcTrivialFieldReads => false,
}
}
pub fn value_str(&self) -> Option<Symbol> {
match self {
GeneratedAttr::AutomaticallyDerived => None,
Expand Down
48 changes: 5 additions & 43 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use std::sync::atomic::{AtomicU32, Ordering};

use rustc_index::bit_set::GrowableBitSet;
use rustc_span::{Ident, Span, Symbol, sym};
use smallvec::{SmallVec, smallvec};
use thin_vec::{ThinVec, thin_vec};

use crate::ast::{
Expand Down Expand Up @@ -135,15 +134,6 @@ impl Attribute {
}
}

pub fn meta_kind(&self) -> Option<MetaItemKind> {
match &self.kind {
AttrKind::Normal(normal) => normal.item.meta_kind(),
AttrKind::Synthetic(..) => unreachable!(),
AttrKind::DocComment(..) => None,
AttrKind::Generated(..) => None,
}
}

pub fn append_token_trees_to(&self, res: &mut Vec<TokenTree>) {
match &self.kind {
AttrKind::Normal(normal) => normal
Expand Down Expand Up @@ -202,15 +192,6 @@ impl Attribute {
AttrKind::Synthetic(..) | AttrKind::DocComment(..) | AttrKind::Generated(..) => None,
}
}

pub fn path_span(&self) -> Option<Span> {
match &self.kind {
AttrKind::Normal(attr) => Some(attr.item.path.span),
AttrKind::Synthetic(..) => unreachable!(),
AttrKind::DocComment(_, _) => None,
AttrKind::Generated(generated) => generated.path_span(),
}
}
}

impl AttrItem {
Expand Down Expand Up @@ -282,6 +263,11 @@ impl AttrItem {
pub fn meta_kind(&self) -> Option<MetaItemKind> {
MetaItemKind::from_attr_args(&self.args)
}

/// Returns whether the attribute is a path, without any arguments.
pub fn is_word(&self) -> bool {
matches!(self.args, AttrArgs::Empty)
}
}

impl MetaItem {
Expand Down Expand Up @@ -891,30 +877,6 @@ impl Attribute {
names.iter().any(|&name| self.has_name(name))
}

/// Returns whether the attribute is a path, without any arguments.
pub fn is_word(&self) -> bool {
match &self.kind {
AttrKind::Normal(normal) => matches!(normal.item.args, AttrArgs::Empty),
AttrKind::Synthetic(..) => unreachable!(),
AttrKind::DocComment(..) => false,
AttrKind::Generated(generated) => generated.is_word(),
}
}

pub fn path(&self) -> SmallVec<[Symbol; 1]> {
use SyntheticAttr::*;
match &self.kind {
AttrKind::Normal(normal) => {
normal.item.path.segments.iter().map(|i| i.ident.name).collect()
}
AttrKind::Synthetic(CfgTrace(_)) => smallvec![sym::cfg],
AttrKind::Synthetic(CfgAttrTrace(_)) => smallvec![sym::cfg_attr],
AttrKind::Synthetic(TestEntrypoint) => smallvec![],
AttrKind::DocComment(_, _) => smallvec![sym::doc],
AttrKind::Generated(generated) => generated.path().iter().copied().collect(),
}
}

/// Returns the documentation if this is a doc comment or a sugared doc comment.
/// * `///doc` returns `Some("doc")`.
/// * `#[doc = "doc"]` returns `Some("doc")`.
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1326,7 +1326,8 @@ impl<'hir> LoweringContext<'_, 'hir> {
// create a fake body so that the entire rest of the compiler doesn't have to deal with
// this as a special case.
return self.lower_fn_body(decl, contract, |this| {
if find_attr!(attrs, RustcIntrinsic) || this.tcx.is_sdylib_interface_build() {
if find_attr!(attrs, RustcIntrinsic { .. }) || this.tcx.is_sdylib_interface_build()
{
let span = this.lower_span(span);
let empty_block = hir::Block {
hir_id: this.next_id(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
args: Default::default(),
constraints: &[],
parenthesized: hir::GenericArgsParentheses::ReturnTypeNotation,
span: data.span,
span: constraint.ident.span.to(data.span),
}
} else {
let guar = self.emit_bad_parenthesized_trait_in_assoc_ty(data);
Expand Down
Loading
Loading