Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
4d0b593
Make `HasTokens` a sub-trait of `HasAttrs`.
nnethercote Jul 12, 2026
7abc537
Suggest the `[const] Destruct` bound for type parameters in const fun…
jakubadamw Apr 8, 2026
4fca6bd
Bless tests affected by the `[const] Destruct` suggestion
jakubadamw Apr 8, 2026
2f961b8
Only offer the `[const] Destruct` suggestion on a nightly compiler
jakubadamw Jul 12, 2026
8c2ed2f
Introduce InstanceKind::LlvmIntrinsic
bjorn3 Jan 8, 2026
aec727f
Stop using EmulateItemResult for LLVM intrinsics in miri
bjorn3 Jul 13, 2026
8583c9a
Add regression test for issue 95719
Joel-Wwalker Jul 13, 2026
d376c08
chore: add codegen test for remainder match
amirHdev Jul 13, 2026
09882ef
inline Once wait and wait_force
vilgotf Jul 13, 2026
9561a52
Bump rustc-perf submodule
Kobzol Jul 13, 2026
5f35fc8
Replace shortened type with `_` instead of `...` as placeholder
estebank Jul 13, 2026
8e12609
Add regression test for issue 144033
Joel-Wwalker Jul 14, 2026
bf52201
Skip intrinsic-test when rustfmt is unavailable
xonx4l Jul 14, 2026
f3f4235
Simplify regression test for issue 144033
Joel-Wwalker Jul 14, 2026
ca15064
Add regression test
oli-obk Jun 12, 2026
5b3e95d
Add regression test
oli-obk Jun 12, 2026
7139a2b
disable range-len-try-from.rs on s390x
fneddy Jul 14, 2026
edbbeae
Update tidy licenses
Kobzol Jul 13, 2026
7d5c925
slice: make swap delegate to swap_unchecked
Rachit2323 Jul 14, 2026
dff3fde
Rename `std_crates_for_run_make` to `std_crates_for_make_run`
Zalathar Jul 14, 2026
070dd68
remove obsolete comment
tshepang Jul 14, 2026
6741f56
Add ´#[rustc_comptime]` inherent impls
oli-obk Jun 12, 2026
29668b5
Construct tokens for attrs made by mk_attr_word
mu001999 Jul 14, 2026
a8019c5
rerun if we meet any opaques in post analysis
adwinwhite Jul 8, 2026
a663cbd
Rollup merge of #157824 - oli-obk:comptime-impls, r=fee1-dead
JonathanBrouwer Jul 14, 2026
c54dc27
Rollup merge of #158993 - adwinwhite:rigid-opaque-in-codegen, r=jdons…
JonathanBrouwer Jul 14, 2026
a81f1b2
Rollup merge of #159160 - nnethercote:HasAttrs-HasTokens, r=petrochenkov
JonathanBrouwer Jul 14, 2026
63361d9
Rollup merge of #159183 - bjorn3:instance_llvm_intrinsic, r=RalfJung,…
JonathanBrouwer Jul 14, 2026
2a68918
Rollup merge of #159251 - Kobzol:update-rustc-perf, r=lqd
JonathanBrouwer Jul 14, 2026
22d3ffe
Rollup merge of #155013 - jakubadamw:issue-103270, r=oli-obk
JonathanBrouwer Jul 14, 2026
1b558e2
Rollup merge of #159235 - Joel-Wwalker:95719-regression-test, r=oli-obk
JonathanBrouwer Jul 14, 2026
583aaa8
Rollup merge of #159239 - amirHdev:add-codegen-test-rem-match-unreach…
JonathanBrouwer Jul 14, 2026
7a69273
Rollup merge of #159243 - vilgotf:once-inline, r=joboet
JonathanBrouwer Jul 14, 2026
3f351b6
Rollup merge of #159255 - estebank:shortened-ty-placeholder, r=Kivooeo
JonathanBrouwer Jul 14, 2026
8bf91af
Rollup merge of #159259 - Joel-Wwalker:144033-regression-test, r=Kivooeo
JonathanBrouwer Jul 14, 2026
8cdf09f
Rollup merge of #159265 - xonx4l:skip-intrinsic-test-missing-rustfmt,…
JonathanBrouwer Jul 14, 2026
403921d
Rollup merge of #159269 - fneddy:disable-test-rltf, r=folkertdev
JonathanBrouwer Jul 14, 2026
8cdcfdf
Rollup merge of #159272 - Rachit2323:fix-slice-swap-use-swap-unchecke…
JonathanBrouwer Jul 14, 2026
ab02230
Rollup merge of #159274 - Zalathar:did-you-mean-make-run, r=jieyouxu
JonathanBrouwer Jul 14, 2026
332ebd9
Rollup merge of #159275 - tshepang:patch-2, r=Kivooeo
JonathanBrouwer Jul 14, 2026
c3cd1da
Rollup merge of #159277 - mu001999-contrib:fix-159261, r=jdonszelmann
JonathanBrouwer Jul 14, 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
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/ast_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl<T: HasNodeId> HasNodeId for Box<T> {
}

/// A trait for AST nodes having (or not having) collected tokens.
pub trait HasTokens {
pub trait HasTokens: HasAttrs {
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>>;
}
Expand Down Expand Up @@ -109,7 +109,7 @@ impl_has_tokens_none!(
WherePredicate
);

impl<T> HasTokens for WithTokens<T> {
impl<T: HasAttrs> HasTokens for WithTokens<T> {
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
self.tokens.as_ref()
}
Expand Down
135 changes: 113 additions & 22 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::fmt::Debug;
use std::sync::atomic::{AtomicU32, Ordering};

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

Expand All @@ -21,7 +21,8 @@ use crate::token::{
self, CommentKind, Delimiter, DocFragmentKind, InvisibleOrigin, MetaVarKind, Token,
};
use crate::tokenstream::{
DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenStreamIter, TokenTree,
AttrTokenStream, AttrTokenTree, DelimSpacing, DelimSpan, LazyAttrTokenStream, Spacing,
TokenStream, TokenStreamIter, TokenTree,
};
use crate::util::comments;
use crate::util::literal::escape_string_symbol;
Expand Down Expand Up @@ -737,23 +738,6 @@ pub fn mk_doc_comment(
Attribute { kind: AttrKind::DocComment(comment_kind, data), id: g.mk_attr_id(), style, span }
}

fn mk_attr(
g: &AttrIdGenerator,
style: AttrStyle,
unsafety: Safety,
path: Path,
args: AttrArgs,
span: Span,
) -> Attribute {
mk_attr_from_item(
g,
AttrItem { unsafety, path, args: AttrItemKind::Unparsed(args) },
None,
style,
span,
)
}

pub fn mk_attr_from_item(
g: &AttrIdGenerator,
item: AttrItem,
Expand All @@ -769,6 +753,50 @@ pub fn mk_attr_from_item(
}
}

fn mk_attr_tokens(
style: AttrStyle,
unsafety: Safety,
item_tokens: AttrTokenStream,
span: Span,
) -> LazyAttrTokenStream {
let safety_kw = match unsafety {
Safety::Default => None,
Safety::Unsafe(span) => Some((kw::Unsafe, span)),
Safety::Safe(span) => Some((kw::Safe, span)),
};
let item_tokens = if let Some((kw, kw_span)) = safety_kw {
AttrTokenStream::new(vec![
AttrTokenTree::Token(Token::from_ast_ident(Ident::new(kw, kw_span)), Spacing::Alone),
AttrTokenTree::Delimited(
DelimSpan::from_single(span),
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
Delimiter::Parenthesis,
item_tokens,
),
])
} else {
item_tokens
};

let mut tokens = match style {
AttrStyle::Outer => {
vec![AttrTokenTree::Token(Token::new(token::Pound, span), Spacing::JointHidden)]
}
AttrStyle::Inner => vec![
AttrTokenTree::Token(Token::new(token::Pound, span), Spacing::Joint),
AttrTokenTree::Token(Token::new(token::Bang, span), Spacing::JointHidden),
],
};
tokens.push(AttrTokenTree::Delimited(
DelimSpan::from_single(span),
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
Delimiter::Bracket,
item_tokens,
));

LazyAttrTokenStream::new_direct(AttrTokenStream::new(tokens))
}

pub fn mk_attr_word(
g: &AttrIdGenerator,
style: AttrStyle,
Expand All @@ -778,7 +806,24 @@ pub fn mk_attr_word(
) -> Attribute {
let path = Path::from_ident(Ident::new(name, span));
let args = AttrArgs::Empty;
mk_attr(g, style, unsafety, path, args, span)

let tokens = Some(mk_attr_tokens(
style,
unsafety,
AttrTokenStream::new(vec![AttrTokenTree::Token(
Token::from_ast_ident(Ident::new(name, span)),
Spacing::Alone,
)]),
span,
));

mk_attr_from_item(
g,
AttrItem { unsafety, path, args: AttrItemKind::Unparsed(args) },
tokens,
style,
span,
)
}

pub fn mk_attr_nested_word(
Expand All @@ -800,7 +845,32 @@ pub fn mk_attr_nested_word(
delim: Delimiter::Parenthesis,
tokens: inner_tokens,
});
mk_attr(g, style, unsafety, path, attr_args, span)

let tokens = Some(mk_attr_tokens(
style,
unsafety,
AttrTokenStream::new(vec![
AttrTokenTree::Token(Token::from_ast_ident(Ident::new(outer, span)), Spacing::Alone),
AttrTokenTree::Delimited(
DelimSpan::from_single(span),
DelimSpacing::new(Spacing::JointHidden, Spacing::Alone),
Delimiter::Parenthesis,
AttrTokenStream::new(vec![AttrTokenTree::Token(
Token::from_ast_ident(Ident::new(inner, span)),
Spacing::Alone,
)]),
),
]),
span,
));

mk_attr_from_item(
g,
AttrItem { unsafety, path, args: AttrItemKind::Unparsed(attr_args) },
tokens,
style,
span,
)
}

pub fn mk_attr_name_value_str(
Expand All @@ -821,7 +891,28 @@ pub fn mk_attr_name_value_str(
});
let path = Path::from_ident(Ident::new(name, span));
let args = AttrArgs::Eq { eq_span: span, expr };
mk_attr(g, style, unsafety, path, args, span)

let tokens = Some(mk_attr_tokens(
style,
unsafety,
AttrTokenStream::new(vec![
AttrTokenTree::Token(Token::from_ast_ident(Ident::new(name, span)), Spacing::Alone),
AttrTokenTree::Token(Token::new(token::Eq, span), Spacing::Alone),
AttrTokenTree::Token(
Token::new(token::TokenKind::lit(lit.kind, lit.symbol, lit.suffix), span),
Spacing::Alone,
),
]),
span,
));

mk_attr_from_item(
g,
AttrItem { unsafety, path, args: AttrItemKind::Unparsed(args) },
tokens,
style,
span,
)
}

pub fn filter_by_name(attrs: &[Attribute], name: Symbol) -> impl Iterator<Item = &Attribute> {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast/src/tokenstream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
use thin_vec::ThinVec;

use crate::ast::AttrStyle;
use crate::ast_traits::{HasAttrs, HasTokens};
use crate::ast_traits::HasTokens;
use crate::token::{self, Delimiter, Token, TokenKind};
use crate::{AttrVec, Attribute};

Expand Down Expand Up @@ -653,7 +653,7 @@ impl TokenStream {
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
}

pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
pub fn from_ast(node: &(impl HasTokens + fmt::Debug)) -> TokenStream {
let tokens = node.tokens().unwrap_or_else(|| panic!("missing tokens for node: {:?}", node));
let mut tts = vec![];
attrs_and_tokens_to_token_trees(node.attrs(), tokens, &mut tts);
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_ast_lowering/src/expr/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
&closure.body,
closure.fn_decl_span,
closure.fn_arg_span,
attrs,
),
span: self.lower_span(e.span),
},
Expand Down Expand Up @@ -240,7 +241,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn_decl_span: self.lower_span(fn_decl_span),
fn_arg_span: Some(self.lower_span(fn_arg_span)),
kind: closure_kind,
constness: self.lower_constness(constness),
constness: self.lower_constness(attrs, constness),
explicit_captures,
});

Expand Down Expand Up @@ -308,6 +309,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
body: &Expr,
fn_decl_span: Span,
fn_arg_span: Span,
attrs: &[hir::Attribute],
) -> hir::ExprKind<'hir> {
let closure_def_id = self.local_def_id(closure_id);
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
Expand Down Expand Up @@ -369,7 +371,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// knows that a `FnDecl` output type like `-> &str` actually means
// "coroutine that returns &str", rather than directly returning a `&str`.
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
constness: self.lower_constness(constness),
constness: self.lower_constness(attrs, constness),
explicit_captures: &[],
});
hir::ExprKind::Closure(c)
Expand Down
45 changes: 25 additions & 20 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
.arena
.alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item)));

let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);

hir::ItemKind::Impl(hir::Impl {
generics,
Expand All @@ -499,7 +499,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
bounds,
items,
}) => {
let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);
let impl_restriction = self.lower_impl_restriction(impl_restriction);
let ident = self.lower_ident(*ident);
let (generics, (safety, items, bounds)) = self.lower_generics(
Expand Down Expand Up @@ -530,7 +530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
}
ItemKind::TraitAlias(TraitAlias { constness, ident, generics, bounds }) => {
let constness = self.lower_constness(*constness);
let constness = self.lower_constness(attrs, *constness);
let ident = self.lower_ident(*ident);
let (generics, bounds) = self.lower_generics(
generics,
Expand Down Expand Up @@ -1702,21 +1702,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
safety.into()
};

let mut constness = self.lower_constness(h.constness);
if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
match std::mem::replace(&mut constness, rustc_hir::Constness::Const { always: true }) {
rustc_hir::Constness::Const { always: true } => {
unreachable!("lower_constness cannot produce comptime")
}
// A function can't be `const` and `comptime` at the same time
rustc_hir::Constness::Const { always: false } => {
let Const::Yes(span) = h.constness else { unreachable!() };
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
}
// Good
rustc_hir::Constness::NotConst => {}
}
}
let constness = self.lower_constness(attrs, h.constness);

hir::FnHeader { safety, asyncness, constness, abi: self.lower_extern(h.ext) }
}
Expand Down Expand Up @@ -1778,11 +1764,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
});
}

pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
match c {
/// Lowers constness or comptime attribute.
/// Whether `const` is allowed here is checked by ast validation.
/// Whether `comptime` is allowed here is checked by the `comptime` attribute parser.
pub(super) fn lower_constness(&mut self, attrs: &[hir::Attribute], c: Const) -> hir::Constness {
let mut constness = match c {
Const::Yes(_) => hir::Constness::Const { always: false },
Const::No => hir::Constness::NotConst,
};

if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
match std::mem::replace(&mut constness, hir::Constness::Const { always: true }) {
hir::Constness::Const { always: true } => {
unreachable!("lower_constness cannot produce comptime")
}
// A function can't be `const` and `comptime` at the same time
hir::Constness::Const { always: false } => {
let Const::Yes(span) = c else { unreachable!() };
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
}
// Good
hir::Constness::NotConst => {}
}
}
constness
}

pub(super) fn lower_safety(&self, s: Safety, default: hir::Safety) -> hir::Safety {
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_attr_parsing/src/attributes/semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl NoArgsAttributeParser for ComptimeParser {
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
Allow(Target::Method(MethodKind::Inherent)),
Allow(Target::Fn),
Allow(Target::Impl { of_trait: false }),
]);
const STABILITY: AttributeStability = unstable!(rustc_attrs);
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcComptime;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_builtin_macros/src/cfg_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use core::ops::ControlFlow;
use rustc_ast as ast;
use rustc_ast::mut_visit::MutVisitor;
use rustc_ast::visit::{AssocCtxt, Visitor};
use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit};
use rustc_ast::{Attribute, HasTokens, NodeId, mut_visit, visit};
use rustc_errors::PResult;
use rustc_expand::base::{Annotatable, ExtCtxt};
use rustc_expand::config::StripUnconfigured;
Expand Down Expand Up @@ -67,7 +67,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
}

impl CfgEval<'_> {
fn configure<T: HasAttrs + HasTokens>(&mut self, node: T) -> Option<T> {
fn configure<T: HasTokens>(&mut self, node: T) -> Option<T> {
self.0.configure(node)
}

Expand Down
23 changes: 11 additions & 12 deletions compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,18 +440,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
}
}

if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
crate::intrinsics::codegen_llvm_intrinsic_call(
fx,
fx.tcx.symbol_name(instance).name,
args,
ret_place,
target,
source_info.span,
);
return;
}

match instance.def {
InstanceKind::Intrinsic(_) => {
match crate::intrinsics::codegen_intrinsic_call(
Expand All @@ -466,6 +454,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
Err(instance) => Some(instance),
}
}
InstanceKind::LlvmIntrinsic(_) => {
crate::intrinsics::codegen_llvm_intrinsic_call(
fx,
fx.tcx.symbol_name(instance).name,
args,
ret_place,
target,
source_info.span,
);
return;
}
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
// it is `func returning noop future`
InstanceKind::Shim(ShimKind::DropGlue(_, None)) => {
Expand Down
Loading
Loading