Skip to content

Commit 59835ae

Browse files
committed
Auto merge of rust-lang#3878 - rust-lang:rustup-2024-09-11, r=RalfJung
Automatic Rustup
2 parents 79d4cc9 + 7e6ce60 commit 59835ae

File tree

272 files changed

+3053
-2377
lines changed

Some content is hidden

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

272 files changed

+3053
-2377
lines changed

compiler/rustc_builtin_macros/src/asm.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,44 @@ pub(super) fn expand_asm<'cx>(
812812
})
813813
}
814814

815+
pub(super) fn expand_naked_asm<'cx>(
816+
ecx: &'cx mut ExtCtxt<'_>,
817+
sp: Span,
818+
tts: TokenStream,
819+
) -> MacroExpanderResult<'cx> {
820+
ExpandResult::Ready(match parse_args(ecx, sp, tts, false) {
821+
Ok(args) => {
822+
let ExpandResult::Ready(mac) = expand_preparsed_asm(ecx, args) else {
823+
return ExpandResult::Retry(());
824+
};
825+
let expr = match mac {
826+
Ok(mut inline_asm) => {
827+
// for future compatibility, we always set the NORETURN option.
828+
//
829+
// When we turn `asm!` into `naked_asm!` with this implementation, we can drop
830+
// the `options(noreturn)`, which makes the upgrade smooth when `naked_asm!`
831+
// starts disallowing the `noreturn` option in the future
832+
inline_asm.options |= ast::InlineAsmOptions::NORETURN;
833+
834+
P(ast::Expr {
835+
id: ast::DUMMY_NODE_ID,
836+
kind: ast::ExprKind::InlineAsm(P(inline_asm)),
837+
span: sp,
838+
attrs: ast::AttrVec::new(),
839+
tokens: None,
840+
})
841+
}
842+
Err(guar) => DummyResult::raw_expr(sp, Some(guar)),
843+
};
844+
MacEager::expr(expr)
845+
}
846+
Err(err) => {
847+
let guar = err.emit();
848+
DummyResult::any(sp, guar)
849+
}
850+
})
851+
}
852+
815853
pub(super) fn expand_global_asm<'cx>(
816854
ecx: &'cx mut ExtCtxt<'_>,
817855
sp: Span,

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
9494
line: source_util::expand_line,
9595
log_syntax: log_syntax::expand_log_syntax,
9696
module_path: source_util::expand_mod,
97+
naked_asm: asm::expand_naked_asm,
9798
option_env: env::expand_option_env,
9899
pattern_type: pattern_type::expand,
99100
std_panic: edition_panic::expand_panic,

compiler/rustc_builtin_macros/src/test_harness.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
326326
let main_attr = ecx.attr_word(sym::rustc_main, sp);
327327
// #[coverage(off)]
328328
let coverage_attr = ecx.attr_nested_word(sym::coverage, sym::off, sp);
329+
// #[allow(missing_docs)]
330+
let missing_docs_attr = ecx.attr_nested_word(sym::allow, sym::missing_docs, sp);
329331

330332
// pub fn main() { ... }
331333
let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()));
@@ -355,7 +357,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
355357

356358
let main = P(ast::Item {
357359
ident: main_id,
358-
attrs: thin_vec![main_attr, coverage_attr],
360+
attrs: thin_vec![main_attr, coverage_attr, missing_docs_attr],
359361
id: ast::DUMMY_NODE_ID,
360362
kind: main,
361363
vis: ast::Visibility { span: sp, kind: ast::VisibilityKind::Public, tokens: None },

compiler/rustc_codegen_cranelift/example/float-minmax-pass.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99

1010
#[repr(simd)]
1111
#[derive(Copy, Clone, PartialEq, Debug)]
12-
struct f32x4(pub f32, pub f32, pub f32, pub f32);
12+
struct f32x4(pub [f32; 4]);
1313

1414
use std::intrinsics::simd::*;
1515

1616
fn main() {
17-
let x = f32x4(1.0, 2.0, 3.0, 4.0);
18-
let y = f32x4(2.0, 1.0, 4.0, 3.0);
17+
let x = f32x4([1.0, 2.0, 3.0, 4.0]);
18+
let y = f32x4([2.0, 1.0, 4.0, 3.0]);
1919

2020
#[cfg(not(any(target_arch = "mips", target_arch = "mips64")))]
2121
let nan = f32::NAN;
@@ -24,13 +24,13 @@ fn main() {
2424
#[cfg(any(target_arch = "mips", target_arch = "mips64"))]
2525
let nan = f32::from_bits(f32::NAN.to_bits() - 1);
2626

27-
let n = f32x4(nan, nan, nan, nan);
27+
let n = f32x4([nan, nan, nan, nan]);
2828

2929
unsafe {
3030
let min0 = simd_fmin(x, y);
3131
let min1 = simd_fmin(y, x);
3232
assert_eq!(min0, min1);
33-
let e = f32x4(1.0, 1.0, 3.0, 3.0);
33+
let e = f32x4([1.0, 1.0, 3.0, 3.0]);
3434
assert_eq!(min0, e);
3535
let minn = simd_fmin(x, n);
3636
assert_eq!(minn, x);
@@ -40,7 +40,7 @@ fn main() {
4040
let max0 = simd_fmax(x, y);
4141
let max1 = simd_fmax(y, x);
4242
assert_eq!(max0, max1);
43-
let e = f32x4(2.0, 2.0, 4.0, 4.0);
43+
let e = f32x4([2.0, 2.0, 4.0, 4.0]);
4444
assert_eq!(max0, e);
4545
let maxn = simd_fmax(x, n);
4646
assert_eq!(maxn, x);

compiler/rustc_codegen_cranelift/example/std_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ fn main() {
166166
enum Never {}
167167
}
168168

169-
foo(I64X2(0, 0));
169+
foo(I64X2([0, 0]));
170170

171171
transmute_fat_pointer();
172172

@@ -204,7 +204,7 @@ fn rust_call_abi() {
204204
}
205205

206206
#[repr(simd)]
207-
struct I64X2(i64, i64);
207+
struct I64X2([i64; 2]);
208208

209209
#[allow(improper_ctypes_definitions)]
210210
extern "C" fn foo(_a: I64X2) {}

compiler/rustc_codegen_gcc/src/back/lto.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,6 @@ fn fat_lto(
272272
}*/
273273
}
274274
};
275-
let mut serialized_bitcode = Vec::new();
276275
{
277276
info!("using {:?} as a base module", module.name);
278277

@@ -317,7 +316,6 @@ fn fat_lto(
317316
unimplemented!("from uncompressed file")
318317
}
319318
}
320-
serialized_bitcode.push(bc_decoded);
321319
}
322320
save_temp_bitcode(cgcx, &module, "lto.input");
323321

@@ -337,7 +335,7 @@ fn fat_lto(
337335
// of now.
338336
module.module_llvm.temp_dir = Some(tmp_path);
339337

340-
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
338+
Ok(LtoModuleCodegen::Fat(module))
341339
}
342340

343341
pub struct ModuleBuffer(PathBuf);

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,6 @@ fn fat_lto(
314314
}
315315
}
316316
};
317-
let mut serialized_bitcode = Vec::new();
318317
{
319318
let (llcx, llmod) = {
320319
let llvm = &module.module_llvm;
@@ -342,9 +341,7 @@ fn fat_lto(
342341
serialized_modules.sort_by(|module1, module2| module1.1.cmp(&module2.1));
343342

344343
// For all serialized bitcode files we parse them and link them in as we did
345-
// above, this is all mostly handled in C++. Like above, though, we don't
346-
// know much about the memory management here so we err on the side of being
347-
// save and persist everything with the original module.
344+
// above, this is all mostly handled in C++.
348345
let mut linker = Linker::new(llmod);
349346
for (bc_decoded, name) in serialized_modules {
350347
let _timer = cgcx
@@ -355,7 +352,6 @@ fn fat_lto(
355352
info!("linking {:?}", name);
356353
let data = bc_decoded.data();
357354
linker.add(data).map_err(|()| write::llvm_err(dcx, LlvmError::LoadBitcode { name }))?;
358-
serialized_bitcode.push(bc_decoded);
359355
}
360356
drop(linker);
361357
save_temp_bitcode(cgcx, &module, "lto.input");
@@ -372,7 +368,7 @@ fn fat_lto(
372368
}
373369
}
374370

375-
Ok(LtoModuleCodegen::Fat { module, _serialized_bitcode: serialized_bitcode })
371+
Ok(LtoModuleCodegen::Fat(module))
376372
}
377373

378374
pub(crate) struct Linker<'a>(&'a mut llvm::Linker<'a>);

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,14 @@ pub struct ThinShared<B: WriteBackendMethods> {
4141
}
4242

4343
pub enum LtoModuleCodegen<B: WriteBackendMethods> {
44-
Fat {
45-
module: ModuleCodegen<B::Module>,
46-
_serialized_bitcode: Vec<SerializedModule<B::ModuleBuffer>>,
47-
},
48-
44+
Fat(ModuleCodegen<B::Module>),
4945
Thin(ThinModule<B>),
5046
}
5147

5248
impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
5349
pub fn name(&self) -> &str {
5450
match *self {
55-
LtoModuleCodegen::Fat { .. } => "everything",
51+
LtoModuleCodegen::Fat(_) => "everything",
5652
LtoModuleCodegen::Thin(ref m) => m.name(),
5753
}
5854
}
@@ -68,7 +64,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
6864
cgcx: &CodegenContext<B>,
6965
) -> Result<ModuleCodegen<B::Module>, FatalError> {
7066
match self {
71-
LtoModuleCodegen::Fat { mut module, .. } => {
67+
LtoModuleCodegen::Fat(mut module) => {
7268
B::optimize_fat(cgcx, &mut module)?;
7369
Ok(module)
7470
}
@@ -81,7 +77,7 @@ impl<B: WriteBackendMethods> LtoModuleCodegen<B> {
8177
pub fn cost(&self) -> u64 {
8278
match *self {
8379
// Only one module with fat LTO, so the cost doesn't matter.
84-
LtoModuleCodegen::Fat { .. } => 0,
80+
LtoModuleCodegen::Fat(_) => 0,
8581
LtoModuleCodegen::Thin(ref m) => m.cost(),
8682
}
8783
}

compiler/rustc_error_codes/src/error_codes/E0074.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This will cause an error:
1111
#![feature(repr_simd)]
1212
1313
#[repr(simd)]
14-
struct Bad<T>(T, T, T, T);
14+
struct Bad<T>([T; 4]);
1515
```
1616

1717
This will not:
@@ -20,5 +20,5 @@ This will not:
2020
#![feature(repr_simd)]
2121
2222
#[repr(simd)]
23-
struct Good(u32, u32, u32, u32);
23+
struct Good([u32; 4]);
2424
```
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
A `#[simd]` attribute was applied to an empty tuple struct.
1+
A `#[simd]` attribute was applied to an empty or multi-field struct.
22

3-
Erroneous code example:
3+
Erroneous code examples:
44

55
```compile_fail,E0075
66
#![feature(repr_simd)]
@@ -9,15 +9,21 @@ Erroneous code example:
99
struct Bad; // error!
1010
```
1111

12-
The `#[simd]` attribute can only be applied to non empty tuple structs, because
13-
it doesn't make sense to try to use SIMD operations when there are no values to
14-
operate on.
12+
```compile_fail,E0075
13+
#![feature(repr_simd)]
14+
15+
#[repr(simd)]
16+
struct Bad([u32; 1], [u32; 1]); // error!
17+
```
18+
19+
The `#[simd]` attribute can only be applied to a single-field struct, because
20+
the one field must be the array of values in the vector.
1521

1622
Fixed example:
1723

1824
```
1925
#![feature(repr_simd)]
2026
2127
#[repr(simd)]
22-
struct Good(u32); // ok!
28+
struct Good([u32; 2]); // ok!
2329
```
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
All types in a tuple struct aren't the same when using the `#[simd]`
1+
The type of the field in a tuple struct isn't an array when using the `#[simd]`
22
attribute.
33

44
Erroneous code example:
@@ -7,18 +7,18 @@ Erroneous code example:
77
#![feature(repr_simd)]
88
99
#[repr(simd)]
10-
struct Bad(u16, u32, u32 u32); // error!
10+
struct Bad(u16); // error!
1111
```
1212

1313
When using the `#[simd]` attribute to automatically use SIMD operations in tuple
14-
struct, the types in the struct must all be of the same type, or the compiler
15-
will trigger this error.
14+
structs, if you want a single-lane vector then the field must be a 1-element
15+
array, or the compiler will trigger this error.
1616

1717
Fixed example:
1818

1919
```
2020
#![feature(repr_simd)]
2121
2222
#[repr(simd)]
23-
struct Good(u32, u32, u32, u32); // ok!
23+
struct Good([u16; 1]); // ok!
2424
```

compiler/rustc_error_codes/src/error_codes/E0077.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Erroneous code example:
77
#![feature(repr_simd)]
88
99
#[repr(simd)]
10-
struct Bad(String); // error!
10+
struct Bad([String; 2]); // error!
1111
```
1212

1313
When using the `#[simd]` attribute on a tuple struct, the elements in the tuple
@@ -19,5 +19,5 @@ Fixed example:
1919
#![feature(repr_simd)]
2020
2121
#[repr(simd)]
22-
struct Good(u32, u32, u32, u32); // ok!
22+
struct Good([u32; 4]); // ok!
2323
```

compiler/rustc_error_codes/src/error_codes/E0511.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ The generic type has to be a SIMD type. Example:
2323
2424
#[repr(simd)]
2525
#[derive(Copy, Clone)]
26-
struct i32x2(i32, i32);
26+
struct i32x2([i32; 2]);
2727
2828
extern "rust-intrinsic" {
2929
fn simd_add<T>(a: T, b: T) -> T;
3030
}
3131
32-
unsafe { simd_add(i32x2(0, 0), i32x2(1, 2)); } // ok!
32+
unsafe { simd_add(i32x2([0, 0]), i32x2([1, 2])); } // ok!
3333
```

compiler/rustc_hir/src/hir.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,19 @@ impl Lifetime {
168168
(LifetimeSuggestionPosition::Normal, self.ident.span)
169169
}
170170
}
171+
172+
pub fn suggestion(&self, new_lifetime: &str) -> (Span, String) {
173+
debug_assert!(new_lifetime.starts_with('\''));
174+
let (pos, span) = self.suggestion_position();
175+
let code = match pos {
176+
LifetimeSuggestionPosition::Normal => format!("{new_lifetime}"),
177+
LifetimeSuggestionPosition::Ampersand => format!("{new_lifetime} "),
178+
LifetimeSuggestionPosition::ElidedPath => format!("<{new_lifetime}>"),
179+
LifetimeSuggestionPosition::ElidedPathArgument => format!("{new_lifetime}, "),
180+
LifetimeSuggestionPosition::ObjectDefault => format!("+ {new_lifetime}"),
181+
};
182+
(span, code)
183+
}
171184
}
172185

173186
/// A `Path` is essentially Rust's notion of a name; for instance,

0 commit comments

Comments
 (0)