Skip to content

Commit 4c9ad9c

Browse files
committed
Auto merge of #159278 - JonathanBrouwer:rollup-CJBoffZ, r=<try>
Rollup of 15 pull requests try-job: dist-various-1 try-job: test-various try-job: x86_64-gnu-aux try-job: x86_64-gnu-llvm-21-3 try-job: x86_64-msvc-1 try-job: aarch64-apple try-job: x86_64-mingw-1 try-job: i686-msvc-*
2 parents da80ed0 + 7fc7316 commit 4c9ad9c

188 files changed

Lines changed: 1209 additions & 664 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

compiler/rustc_ast/src/ast_traits.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl<T: HasNodeId> HasNodeId for Box<T> {
6262
}
6363

6464
/// A trait for AST nodes having (or not having) collected tokens.
65-
pub trait HasTokens {
65+
pub trait HasTokens: HasAttrs {
6666
fn tokens(&self) -> Option<&LazyAttrTokenStream>;
6767
fn tokens_mut(&mut self) -> Option<&mut Option<LazyAttrTokenStream>>;
6868
}
@@ -109,7 +109,7 @@ impl_has_tokens_none!(
109109
WherePredicate
110110
);
111111

112-
impl<T> HasTokens for WithTokens<T> {
112+
impl<T: HasAttrs> HasTokens for WithTokens<T> {
113113
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
114114
self.tokens.as_ref()
115115
}

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_span::{DUMMY_SP, Span, SpanDecoder, SpanEncoder, Symbol, sym};
1818
use thin_vec::ThinVec;
1919

2020
use crate::ast::AttrStyle;
21-
use crate::ast_traits::{HasAttrs, HasTokens};
21+
use crate::ast_traits::HasTokens;
2222
use crate::token::{self, Delimiter, Token, TokenKind};
2323
use crate::{AttrVec, Attribute};
2424

@@ -653,7 +653,7 @@ impl TokenStream {
653653
TokenStream::new(vec![TokenTree::token_alone(kind, span)])
654654
}
655655

656-
pub fn from_ast(node: &(impl HasAttrs + HasTokens + fmt::Debug)) -> TokenStream {
656+
pub fn from_ast(node: &(impl HasTokens + fmt::Debug)) -> TokenStream {
657657
let tokens = node.tokens().unwrap_or_else(|| panic!("missing tokens for node: {:?}", node));
658658
let mut tts = vec![];
659659
attrs_and_tokens_to_token_trees(node.attrs(), tokens, &mut tts);

compiler/rustc_ast_lowering/src/expr/closure.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
3838
&closure.body,
3939
closure.fn_decl_span,
4040
closure.fn_arg_span,
41+
attrs,
4142
),
4243
span: self.lower_span(e.span),
4344
},
@@ -240,7 +241,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
240241
fn_decl_span: self.lower_span(fn_decl_span),
241242
fn_arg_span: Some(self.lower_span(fn_arg_span)),
242243
kind: closure_kind,
243-
constness: self.lower_constness(constness),
244+
constness: self.lower_constness(attrs, constness),
244245
explicit_captures,
245246
});
246247

@@ -308,6 +309,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
308309
body: &Expr,
309310
fn_decl_span: Span,
310311
fn_arg_span: Span,
312+
attrs: &[hir::Attribute],
311313
) -> hir::ExprKind<'hir> {
312314
let closure_def_id = self.local_def_id(closure_id);
313315
let (binder_clause, generic_params) = self.lower_closure_binder(binder);
@@ -369,7 +371,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
369371
// knows that a `FnDecl` output type like `-> &str` actually means
370372
// "coroutine that returns &str", rather than directly returning a `&str`.
371373
kind: hir::ClosureKind::CoroutineClosure(coroutine_desugaring),
372-
constness: self.lower_constness(constness),
374+
constness: self.lower_constness(attrs, constness),
373375
explicit_captures: &[],
374376
});
375377
hir::ExprKind::Closure(c)

compiler/rustc_ast_lowering/src/item.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
479479
.arena
480480
.alloc_from_iter(impl_items.iter().map(|item| self.lower_impl_item_ref(item)));
481481

482-
let constness = self.lower_constness(*constness);
482+
let constness = self.lower_constness(attrs, *constness);
483483

484484
hir::ItemKind::Impl(hir::Impl {
485485
generics,
@@ -499,7 +499,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
499499
bounds,
500500
items,
501501
}) => {
502-
let constness = self.lower_constness(*constness);
502+
let constness = self.lower_constness(attrs, *constness);
503503
let impl_restriction = self.lower_impl_restriction(impl_restriction);
504504
let ident = self.lower_ident(*ident);
505505
let (generics, (safety, items, bounds)) = self.lower_generics(
@@ -530,7 +530,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
530530
}
531531
}
532532
ItemKind::TraitAlias(TraitAlias { constness, ident, generics, bounds }) => {
533-
let constness = self.lower_constness(*constness);
533+
let constness = self.lower_constness(attrs, *constness);
534534
let ident = self.lower_ident(*ident);
535535
let (generics, bounds) = self.lower_generics(
536536
generics,
@@ -1702,21 +1702,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
17021702
safety.into()
17031703
};
17041704

1705-
let mut constness = self.lower_constness(h.constness);
1706-
if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
1707-
match std::mem::replace(&mut constness, rustc_hir::Constness::Const { always: true }) {
1708-
rustc_hir::Constness::Const { always: true } => {
1709-
unreachable!("lower_constness cannot produce comptime")
1710-
}
1711-
// A function can't be `const` and `comptime` at the same time
1712-
rustc_hir::Constness::Const { always: false } => {
1713-
let Const::Yes(span) = h.constness else { unreachable!() };
1714-
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
1715-
}
1716-
// Good
1717-
rustc_hir::Constness::NotConst => {}
1718-
}
1719-
}
1705+
let constness = self.lower_constness(attrs, h.constness);
17201706

17211707
hir::FnHeader { safety, asyncness, constness, abi: self.lower_extern(h.ext) }
17221708
}
@@ -1778,11 +1764,30 @@ impl<'hir> LoweringContext<'_, 'hir> {
17781764
});
17791765
}
17801766

1781-
pub(super) fn lower_constness(&mut self, c: Const) -> hir::Constness {
1782-
match c {
1767+
/// Lowers constness or comptime attribute.
1768+
/// Whether `const` is allowed here is checked by ast validation.
1769+
/// Whether `comptime` is allowed here is checked by the `comptime` attribute parser.
1770+
pub(super) fn lower_constness(&mut self, attrs: &[hir::Attribute], c: Const) -> hir::Constness {
1771+
let mut constness = match c {
17831772
Const::Yes(_) => hir::Constness::Const { always: false },
17841773
Const::No => hir::Constness::NotConst,
1774+
};
1775+
1776+
if let Some(&attr_span) = find_attr!(attrs, RustcComptime(span) => span) {
1777+
match std::mem::replace(&mut constness, hir::Constness::Const { always: true }) {
1778+
hir::Constness::Const { always: true } => {
1779+
unreachable!("lower_constness cannot produce comptime")
1780+
}
1781+
// A function can't be `const` and `comptime` at the same time
1782+
hir::Constness::Const { always: false } => {
1783+
let Const::Yes(span) = c else { unreachable!() };
1784+
self.dcx().emit_err(ConstComptimeFn { span, attr_span });
1785+
}
1786+
// Good
1787+
hir::Constness::NotConst => {}
1788+
}
17851789
}
1790+
constness
17861791
}
17871792

17881793
pub(super) fn lower_safety(&self, s: Safety, default: hir::Safety) -> hir::Safety {

compiler/rustc_attr_parsing/src/attributes/semantics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ impl NoArgsAttributeParser for ComptimeParser {
2323
const ALLOWED_TARGETS: AllowedTargets<'_> = AllowedTargets::AllowList(&[
2424
Allow(Target::Method(MethodKind::Inherent)),
2525
Allow(Target::Fn),
26+
Allow(Target::Impl { of_trait: false }),
2627
]);
2728
const STABILITY: AttributeStability = unstable!(rustc_attrs);
2829
const CREATE: fn(Span) -> AttributeKind = AttributeKind::RustcComptime;

compiler/rustc_builtin_macros/src/cfg_eval.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use core::ops::ControlFlow;
33
use rustc_ast as ast;
44
use rustc_ast::mut_visit::MutVisitor;
55
use rustc_ast::visit::{AssocCtxt, Visitor};
6-
use rustc_ast::{Attribute, HasAttrs, HasTokens, NodeId, mut_visit, visit};
6+
use rustc_ast::{Attribute, HasTokens, NodeId, mut_visit, visit};
77
use rustc_errors::PResult;
88
use rustc_expand::base::{Annotatable, ExtCtxt};
99
use rustc_expand::config::StripUnconfigured;
@@ -67,7 +67,7 @@ fn has_cfg_or_cfg_attr(annotatable: &Annotatable) -> bool {
6767
}
6868

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

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -440,18 +440,6 @@ pub(crate) fn codegen_terminator_call<'tcx>(
440440
}
441441
}
442442

443-
if fx.tcx.symbol_name(instance).name.starts_with("llvm.") {
444-
crate::intrinsics::codegen_llvm_intrinsic_call(
445-
fx,
446-
fx.tcx.symbol_name(instance).name,
447-
args,
448-
ret_place,
449-
target,
450-
source_info.span,
451-
);
452-
return;
453-
}
454-
455443
match instance.def {
456444
InstanceKind::Intrinsic(_) => {
457445
match crate::intrinsics::codegen_intrinsic_call(
@@ -466,6 +454,17 @@ pub(crate) fn codegen_terminator_call<'tcx>(
466454
Err(instance) => Some(instance),
467455
}
468456
}
457+
InstanceKind::LlvmIntrinsic(_) => {
458+
crate::intrinsics::codegen_llvm_intrinsic_call(
459+
fx,
460+
fx.tcx.symbol_name(instance).name,
461+
args,
462+
ret_place,
463+
target,
464+
source_info.span,
465+
);
466+
return;
467+
}
469468
// We don't need AsyncDropGlueCtorShim here because it is not `noop func`,
470469
// it is `func returning noop future`
471470
InstanceKind::Shim(ShimKind::DropGlue(_, None)) => {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ fn visibility_di_flags<'ll, 'tcx>(
10441044
match visibility {
10451045
Visibility::Public => DIFlags::FlagPublic,
10461046
// Private fields have a restricted visibility of the module containing the type.
1047-
Visibility::Restricted(did) if did == parent_did => DIFlags::FlagPrivate,
1047+
Visibility::Restricted(did) if did.to_def_id() == parent_did => DIFlags::FlagPrivate,
10481048
// `pub(crate)`/`pub(super)` visibilities are any other restricted visibility.
10491049
Visibility::Restricted(..) => DIFlags::FlagProtected,
10501050
}

compiler/rustc_codegen_ssa/src/base.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -892,12 +892,8 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
892892
tcx: TyCtxt<'tcx>,
893893
instance: Instance<'tcx>,
894894
) -> bool {
895-
fn is_llvm_intrinsic(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
896-
if let Some(name) = tcx.codegen_fn_attrs(def_id).symbol_name {
897-
name.as_str().starts_with("llvm.")
898-
} else {
899-
false
900-
}
895+
if let ty::InstanceKind::LlvmIntrinsic(_) = instance.def {
896+
return false;
901897
}
902898

903899
fn is_extern_call_to_local_crate<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) -> bool {
@@ -910,7 +906,6 @@ pub fn is_call_from_compiler_builtins_to_upstream_monomorphization<'tcx>(
910906
let def_id = instance.def_id();
911907
!def_id.is_local()
912908
&& tcx.is_compiler_builtins(LOCAL_CRATE)
913-
&& !is_llvm_intrinsic(tcx, def_id)
914909
&& !tcx.should_codegen_locally(instance)
915910
&& !is_extern_call_to_local_crate(tcx, instance)
916911
}

compiler/rustc_codegen_ssa/src/mir/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1112,8 +1112,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11121112
};
11131113

11141114
if let Some(instance) = instance
1115+
&& let ty::InstanceKind::LlvmIntrinsic(_) = instance.def
11151116
&& let Some(name) = bx.tcx().codegen_fn_attrs(instance.def_id()).symbol_name
1116-
&& name.as_str().starts_with("llvm.")
11171117
// This is the only LLVM intrinsic we use that unwinds
11181118
// FIXME either add unwind support to codegen_llvm_intrinsic_call or replace usage of
11191119
// this intrinsic with something else

0 commit comments

Comments
 (0)