Skip to content

Commit 6b05f82

Browse files
committed
Auto merge of #165844 - Zalathar:rollup-BB6Dp3b, r=Zalathar
Rollup of 11 pull requests Successful merges: - #165804 (cg_llvm: Use an invariant lifetime brand for LLVM values) - #165778 (Bump stage0 to 1.101.0-beta.1) - #165412 (Implement `core::ops::FnAddr`) - #165487 (Migrate built-in macros `pattern_type` & `view_type` to macros 2.0 that expand to internal syntax) - #165818 (do not lint `redundant_lifetimes` on items from external macros) - #163077 (feat: support nested functions with `#[offload_kernel]`) - #164795 (Extend support of lint `explicit_outlives_requirements` to checked type aliases) - #165578 (Avoid `Hash::hash` when stable-hashing various types) - #165729 (tests: Add regression test for infinite recursive dereference) - #165822 (Remove unused compiler modules and types) - #165824 (Add regression test for HRTB projection bound with TryFrom error)
2 parents ee8268e + b8a88ea commit 6b05f82

274 files changed

Lines changed: 3985 additions & 3842 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_abi/src/extern_abi.rs‎

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,19 +241,33 @@ impl PartialEq for ExternAbi {
241241

242242
impl Eq for ExternAbi {}
243243

244+
impl ExternAbi {
245+
/// Common implementation for `Hash` and `StableHash`.
246+
fn stable_hash_inner(&self, hasher: &mut impl Hasher) {
247+
// To avoid staging inconsistencies in stable hashing, we must not rely
248+
// on any stdlib-provided or stdlib-derived impl of `Hash`.
249+
// See <https://github.com/rust-lang/rust/issues/164734> for context.
250+
251+
// Hardcoded copy of the unstable `Hasher::write_str`, with an explicit terminator.
252+
hasher.write(self.as_str().as_bytes());
253+
hasher.write_u8(0xFF);
254+
255+
// double-assurance of a prefix breaker
256+
hasher.write_u32(u32::from_be_bytes(*b"ABI\0"));
257+
}
258+
}
259+
244260
impl Hash for ExternAbi {
245261
fn hash<H: Hasher>(&self, state: &mut H) {
246-
self.as_str().hash(state);
247-
// double-assurance of a prefix breaker
248-
u32::from_be_bytes(*b"ABI\0").hash(state);
262+
self.stable_hash_inner(state);
249263
}
250264
}
251265

252266
#[cfg(feature = "nightly")]
253267
impl StableHash for ExternAbi {
254268
#[inline]
255269
fn stable_hash<Hcx: StableHashCtxt>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
256-
Hash::hash(self, hasher);
270+
self.stable_hash_inner(hasher);
257271
}
258272
}
259273

‎compiler/rustc_arena/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
// tidy-alphabetical-start
1111
#![allow(clippy::mut_from_ref)] // Arena allocators are one place where this pattern is fine.
1212
#![allow(internal_features)]
13-
#![cfg_attr(bootstrap, feature(unwrap_infallible))]
1413
#![cfg_attr(test, feature(test))]
1514
#![deny(unsafe_op_in_unsafe_fn)]
1615
#![doc(test(no_crate_inject, attr(deny(warnings))))]

‎compiler/rustc_ast_passes/src/feature_gate.rs‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,6 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
241241
// Function pointers cannot be `const`
242242
self.check_late_bound_lifetime_defs(&fn_ptr_ty.generic_params);
243243
}
244-
ast::TyKind::Pat(..) => {
245-
gate!(self, pattern_types, ty.span, "pattern types are unstable");
246-
}
247-
ast::TyKind::View(..) => {
248-
gate!(self, view_types, ty.span, "view types are unstable");
249-
}
250244
_ => {}
251245
}
252246
visit::walk_ty(self, ty)
@@ -469,7 +463,6 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
469463
gate_all!(unnamed_enum_variants, "unnamed enum variants are experimental");
470464
gate_all!(unsafe_binders, "unsafe binder types are experimental");
471465
gate_all!(unsafe_fields, "`unsafe` fields are experimental");
472-
gate_all!(view_types, "view types are experimental");
473466
gate_all!(where_clause_attrs, "attributes in `where` clause are unstable");
474467
gate_all!(yeet_expr, "`do yeet` expression is experimental");
475468
// tidy-alphabetical-end

‎compiler/rustc_ast_pretty/src/pprust/state.rs‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,9 +1437,12 @@ impl<'a> State<'a> {
14371437
self.word("...");
14381438
}
14391439
ast::TyKind::Pat(ty, pat) => {
1440+
self.word("k#pattern_type");
1441+
self.popen();
14401442
self.print_type(ty);
14411443
self.word(" is ");
14421444
self.print_ty_pat(pat);
1445+
self.pclose();
14431446
}
14441447
ast::TyKind::FieldOf(ty, variant, field) => {
14451448
self.word("k#field_of");
@@ -1459,8 +1462,11 @@ impl<'a> State<'a> {
14591462
self.pclose();
14601463
}
14611464
ast::TyKind::View(ty, fields) => {
1465+
self.word("k#view_type");
1466+
self.popen();
14621467
self.print_type(ty);
14631468
self.print_view(fields);
1469+
self.pclose();
14641470
}
14651471
ast::TyKind::GcaMacro(expr) => {
14661472
self.word_nbsp("core::gca!");

‎compiler/rustc_ast_pretty/src/pprust/tests.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ fn test_field_view() {
8080
};
8181

8282
let ty_str = ty_to_string(&ty);
83-
assert_eq!(ty_str, "(/*DUMMY*/).{ milhouse, apu }");
83+
assert_eq!(ty_str, "k#view_type((/*DUMMY*/).{ milhouse, apu })");
8484
});
8585
}

‎compiler/rustc_attr_ir/src/lang_items.rs‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
//! * Functions called by the compiler itself.
99
1010
use rustc_data_structures::fx::FxIndexMap;
11-
use rustc_data_structures::stable_hash::{StableHash, StableHashCtxt, StableHasher};
1211
use rustc_macros::{BlobDecodable, Encodable, PrintAttribute, StableHash};
1312
use rustc_span::def_id::DefId;
1413
use rustc_span::{Symbol, kw, sym};
@@ -80,7 +79,7 @@ macro_rules! language_item_table {
8079
$( $(#[$attr:meta])* $variant:ident, $module:ident :: $name:ident, $method:ident, $target:expr, $generics:expr; )*
8180
) => {
8281
/// A representation of all the valid lang items in Rust.
83-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, Encodable, BlobDecodable, PrintAttribute)]
82+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash, StableHash, Encodable, BlobDecodable, PrintAttribute)]
8483
pub enum LangItem {
8584
$(
8685
#[doc = concat!("The `", stringify!($name), "` lang item.")]
@@ -149,12 +148,6 @@ macro_rules! language_item_table {
149148
}
150149
}
151150

152-
impl StableHash for LangItem {
153-
fn stable_hash<Hcx: StableHashCtxt>(&self, _: &mut Hcx, hasher: &mut StableHasher) {
154-
::std::hash::Hash::hash(self, hasher);
155-
}
156-
}
157-
158151
language_item_table! {
159152
// Variant name, Name, Getter method name, Target Generic requirements;
160153
Sized, sym::sized, sized_trait, Target::Trait, GenericRequirement::Exact(0);
@@ -187,7 +180,9 @@ language_item_table! {
187180
UnsafeUnpin, sym::unsafe_unpin, unsafe_unpin_trait, Target::Trait, GenericRequirement::Exact(0);
188181

189182
FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0);
190-
FnPtrAsPtr, sym::fn_ptr_as_ptr, fn_ptr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
183+
FnAddrTrait, sym::fn_addr_trait, fn_addr_trait, Target::Trait, GenericRequirement::Exact(0);
184+
FnAddrAsPtr, sym::fn_addr_as_ptr, fn_addr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
185+
FnAddrAddrFn, sym::fn_addr_addr_fn, fn_addr_addr_fn, Target::Method(MethodKind::Trait { body: true }), GenericRequirement::None;
191186
FnPtrFromPtr, sym::fn_ptr_from_ptr, fn_ptr_from_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
192187
Code, sym::code, code, Target::ForeignTy, GenericRequirement::None;
193188

‎compiler/rustc_builtin_macros/src/diagnostics.rs‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,13 @@ mod autodiff {
229229
}
230230
}
231231

232+
#[derive(Diagnostic)]
233+
#[diag("offload_kernel must be applied to function")]
234+
pub(crate) struct OffloadKernelInvalidApplication {
235+
#[primary_span]
236+
pub(crate) span: Span,
237+
}
238+
232239
#[derive(Diagnostic)]
233240
#[diag("cannot concatenate {$lit_kind} literals")]
234241
pub(crate) struct ConcatBytesInvalid {

‎compiler/rustc_builtin_macros/src/lib.rs‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,11 @@ mod global_allocator;
4545
mod iter;
4646
mod log_syntax;
4747
mod offload;
48-
mod pattern_type;
4948
mod rustdoc_skip_body;
5049
mod source_util;
5150
mod test;
5251
mod test_binder_constraints;
5352
mod trace_macros;
54-
mod view_type;
5553

5654
pub mod asm;
5755
pub mod cmdline_attrs;
@@ -100,13 +98,11 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
10098
module_path: source_util::expand_mod,
10199
naked_asm: asm::expand_naked_asm,
102100
option_env: env::expand_option_env,
103-
pattern_type: pattern_type::expand,
104101
std_panic: edition_panic::expand_panic,
105102
stringify: source_util::expand_stringify,
106103
test_binder_constraints: test_binder_constraints::expand,
107104
trace_macros: trace_macros::expand_trace_macros,
108105
unreachable: edition_panic::expand_unreachable,
109-
view_type: view_type::expand,
110106
// tidy-alphabetical-end
111107
}
112108

‎compiler/rustc_builtin_macros/src/offload.rs‎

Lines changed: 42 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,26 @@ fn outer_normal_attr(normal: &Box<ast::NormalAttr>, id: ast::AttrId, span: Span)
2121
fn extract_fn(
2222
item: &Annotatable,
2323
) -> Option<(ast::Visibility, ast::FnSig, Ident, ast::Generics, Option<Box<ast::Block>>)> {
24-
match item {
25-
Annotatable::Item(iitem) => match &iitem.kind {
26-
ast::ItemKind::Fn(ast::Fn { sig, ident, generics, body, .. }) => {
27-
Some((iitem.vis.clone(), sig.clone(), *ident, generics.clone(), body.clone()))
28-
}
29-
_ => None,
30-
},
24+
let fn_item_kind_and_vis = match item {
25+
Annotatable::Item(iitem) => Some((&iitem.kind, &iitem.vis)),
26+
Annotatable::Stmt(stmt) if let ast::StmtKind::Item(iitem) = &stmt.kind => {
27+
Some((&iitem.kind, &iitem.vis))
28+
}
3129
_ => None,
30+
};
31+
32+
if let Some((item_kind, visibility)) = fn_item_kind_and_vis
33+
&& let ast::ItemKind::Fn(kind) = item_kind
34+
{
35+
Some((
36+
visibility.clone(),
37+
kind.sig.clone(),
38+
kind.ident,
39+
kind.generics.clone(),
40+
kind.body.clone(),
41+
))
42+
} else {
43+
None
3244
}
3345
}
3446

@@ -68,7 +80,7 @@ pub(crate) fn expand_kernel(
6880
let dcx = ecx.sess.dcx();
6981

7082
let Some((vis, sig, ident, generics, body)) = extract_fn(&item) else {
71-
dcx.emit_err(diagnostics::AutoDiffInvalidApplication { span: item.span() });
83+
dcx.emit_err(diagnostics::OffloadKernelInvalidApplication { span: item.span() });
7284
return vec![item];
7385
};
7486

@@ -100,10 +112,19 @@ pub(crate) fn expand_kernel(
100112
);
101113

102114
let device_item = {
103-
let mut item =
115+
let mut device_item_ecx =
104116
ecx.item(span, thin_vec![rustc_offload_kernel.clone()], ast::ItemKind::Fn(device_fn));
105-
item.vis = vis.clone();
106-
Annotatable::Item(item)
117+
device_item_ecx.vis = vis.clone();
118+
119+
match &item {
120+
Annotatable::Item(_) => Annotatable::Item(device_item_ecx),
121+
Annotatable::Stmt(_) => {
122+
Annotatable::Stmt(Box::new(ecx.stmt_item(span, device_item_ecx)))
123+
}
124+
_ => {
125+
unreachable!("item kind checked previously")
126+
}
127+
}
107128
};
108129

109130
// unimplemented! body
@@ -150,13 +171,20 @@ pub(crate) fn expand_kernel(
150171
let inline_never = outer_normal_attr(&inline_never_attr, new_id, span);
151172

152173
let host_item = {
153-
let mut item = ecx.item(
174+
let mut host_item_ecx = ecx.item(
154175
span,
155176
thin_vec![rustc_offload_kernel, inline_never],
156177
ast::ItemKind::Fn(host_fn),
157178
);
158-
item.vis = vis;
159-
Annotatable::Item(item)
179+
host_item_ecx.vis = vis;
180+
181+
match &item {
182+
Annotatable::Item(_) => Annotatable::Item(host_item_ecx),
183+
Annotatable::Stmt(_) => Annotatable::Stmt(Box::new(ecx.stmt_item(span, host_item_ecx))),
184+
_ => {
185+
unreachable!("item kind checked previously")
186+
}
187+
}
160188
};
161189

162190
if compile_for_device(ecx) { vec![device_item] } else { vec![host_item] }

‎compiler/rustc_builtin_macros/src/pattern_type.rs‎

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)