Skip to content

Commit ebd08d8

Browse files
committed
Auto merge of #128634 - matthiaskrgr:rollup-l5a2v5k, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #128305 (improve error message when `global_asm!` uses `asm!` operands) - #128526 (time.rs: remove "Basic usage text") - #128531 (Miri: add a flag to do recursive validity checking) - #128578 (rustdoc: Cleanup `CacheBuilder` code for building search index) - #128589 (allow setting `link-shared` and `static-libstdcpp` with CI LLVM) - #128615 (rustdoc: make the hover trail for doc anchors a bit bigger) - #128620 (Update rinja version to 0.3.0) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 58fb508 + f1c4c0f commit ebd08d8

File tree

26 files changed

+472
-300
lines changed

26 files changed

+472
-300
lines changed

Cargo.lock

+9-6
Original file line numberDiff line numberDiff line change
@@ -3282,20 +3282,22 @@ dependencies = [
32823282

32833283
[[package]]
32843284
name = "rinja"
3285-
version = "0.2.0"
3285+
version = "0.3.0"
32863286
source = "registry+https://github.com/rust-lang/crates.io-index"
3287-
checksum = "d2d47a46d7729e891c8accf260e9daa02ae6d570aa2a94fb1fb27eb5364a2323"
3287+
checksum = "6d3762e3740cdbf2fd2be465cc2c26d643ad17353cc2e0223d211c1b096118bd"
32883288
dependencies = [
3289+
"itoa",
32893290
"rinja_derive",
32903291
]
32913292

32923293
[[package]]
32933294
name = "rinja_derive"
3294-
version = "0.2.0"
3295+
version = "0.3.0"
32953296
source = "registry+https://github.com/rust-lang/crates.io-index"
3296-
checksum = "44dae9afe59d58ed8d988d67d1945f3638125d2fd2104058399382e11bd3ea2a"
3297+
checksum = "fd01fd8e15e7d19c8b8052c1d428325131e02ff1633cdcf695190c2e56ab682c"
32973298
dependencies = [
32983299
"basic-toml",
3300+
"memchr",
32993301
"mime",
33003302
"mime_guess",
33013303
"once_map",
@@ -3308,10 +3310,11 @@ dependencies = [
33083310

33093311
[[package]]
33103312
name = "rinja_parser"
3311-
version = "0.2.0"
3313+
version = "0.3.0"
33123314
source = "registry+https://github.com/rust-lang/crates.io-index"
3313-
checksum = "1b1771c78cd5d3b1646ef8d8f2ed100db936e8b291d3cc06e92a339ff346858c"
3315+
checksum = "a2f6bf7cef118c6de21206edf0b3f19f5ede60006be674a58ca21b6e003a1b57"
33143316
dependencies = [
3317+
"memchr",
33153318
"nom",
33163319
]
33173320

compiler/rustc_builtin_macros/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ builtin_macros_format_use_positional = consider using a positional formatting ar
196196
197197
builtin_macros_global_asm_clobber_abi = `clobber_abi` cannot be used with `global_asm!`
198198
199+
builtin_macros_global_asm_unsupported_operand = the `{$symbol}` operand cannot be used with `global_asm!`
200+
.label = the `{$symbol}` operand is not meaningful for global-scoped inline assembly, remove it
201+
199202
builtin_macros_global_asm_unsupported_option = the `{$symbol}` option cannot be used with `global_asm!`
200203
.label = the `{$symbol}` option is not meaningful for global-scoped inline assembly
201204
.suggestion = remove this option

compiler/rustc_builtin_macros/src/asm.rs

+31-8
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,29 @@ pub struct AsmArgs {
2828
pub options_spans: Vec<Span>,
2929
}
3030

31+
/// Used for better error messages when operand types are used that are not
32+
/// supported by the current macro (e.g. `in` or `out` for `global_asm!`)
33+
///
34+
/// returns
35+
///
36+
/// - `Ok(true)` if the current token matches the keyword, and was expected
37+
/// - `Ok(false)` if the current token does not match the keyword
38+
/// - `Err(_)` if the current token matches the keyword, but was not expected
39+
fn eat_operand_keyword<'a>(p: &mut Parser<'a>, symbol: Symbol, expect: bool) -> PResult<'a, bool> {
40+
if expect {
41+
Ok(p.eat_keyword(symbol))
42+
} else {
43+
let span = p.token.span;
44+
if p.eat_keyword_noexpect(symbol) {
45+
// in gets printed as `r#in` otherwise
46+
let symbol = if symbol == kw::In { "in" } else { symbol.as_str() };
47+
Err(p.dcx().create_err(errors::GlobalAsmUnsupportedOperand { span, symbol }))
48+
} else {
49+
Ok(false)
50+
}
51+
}
52+
}
53+
3154
fn parse_args<'a>(
3255
ecx: &ExtCtxt<'a>,
3356
sp: Span,
@@ -105,23 +128,23 @@ pub fn parse_asm_args<'a>(
105128
};
106129

107130
let mut explicit_reg = false;
108-
let op = if !is_global_asm && p.eat_keyword(kw::In) {
131+
let op = if eat_operand_keyword(p, kw::In, !is_global_asm)? {
109132
let reg = parse_reg(p, &mut explicit_reg)?;
110133
if p.eat_keyword(kw::Underscore) {
111134
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
112135
return Err(err);
113136
}
114137
let expr = p.parse_expr()?;
115138
ast::InlineAsmOperand::In { reg, expr }
116-
} else if !is_global_asm && p.eat_keyword(sym::out) {
139+
} else if eat_operand_keyword(p, sym::out, !is_global_asm)? {
117140
let reg = parse_reg(p, &mut explicit_reg)?;
118141
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
119142
ast::InlineAsmOperand::Out { reg, expr, late: false }
120-
} else if !is_global_asm && p.eat_keyword(sym::lateout) {
143+
} else if eat_operand_keyword(p, sym::lateout, !is_global_asm)? {
121144
let reg = parse_reg(p, &mut explicit_reg)?;
122145
let expr = if p.eat_keyword(kw::Underscore) { None } else { Some(p.parse_expr()?) };
123146
ast::InlineAsmOperand::Out { reg, expr, late: true }
124-
} else if !is_global_asm && p.eat_keyword(sym::inout) {
147+
} else if eat_operand_keyword(p, sym::inout, !is_global_asm)? {
125148
let reg = parse_reg(p, &mut explicit_reg)?;
126149
if p.eat_keyword(kw::Underscore) {
127150
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
@@ -135,7 +158,7 @@ pub fn parse_asm_args<'a>(
135158
} else {
136159
ast::InlineAsmOperand::InOut { reg, expr, late: false }
137160
}
138-
} else if !is_global_asm && p.eat_keyword(sym::inlateout) {
161+
} else if eat_operand_keyword(p, sym::inlateout, !is_global_asm)? {
139162
let reg = parse_reg(p, &mut explicit_reg)?;
140163
if p.eat_keyword(kw::Underscore) {
141164
let err = dcx.create_err(errors::AsmUnderscoreInput { span: p.token.span });
@@ -149,6 +172,9 @@ pub fn parse_asm_args<'a>(
149172
} else {
150173
ast::InlineAsmOperand::InOut { reg, expr, late: true }
151174
}
175+
} else if eat_operand_keyword(p, sym::label, !is_global_asm)? {
176+
let block = p.parse_block()?;
177+
ast::InlineAsmOperand::Label { block }
152178
} else if p.eat_keyword(kw::Const) {
153179
let anon_const = p.parse_expr_anon_const()?;
154180
ast::InlineAsmOperand::Const { anon_const }
@@ -164,9 +190,6 @@ pub fn parse_asm_args<'a>(
164190
path: path.clone(),
165191
};
166192
ast::InlineAsmOperand::Sym { sym }
167-
} else if !is_global_asm && p.eat_keyword(sym::label) {
168-
let block = p.parse_block()?;
169-
ast::InlineAsmOperand::Label { block }
170193
} else if allow_templates {
171194
let template = p.parse_expr()?;
172195
// If it can't possibly expand to a string, provide diagnostics here to include other

compiler/rustc_builtin_macros/src/errors.rs

+9
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,15 @@ pub(crate) struct GlobalAsmUnsupportedOption {
851851
pub(crate) full_span: Span,
852852
}
853853

854+
#[derive(Diagnostic)]
855+
#[diag(builtin_macros_global_asm_unsupported_operand)]
856+
pub(crate) struct GlobalAsmUnsupportedOperand<'a> {
857+
#[primary_span]
858+
#[label]
859+
pub(crate) span: Span,
860+
pub(crate) symbol: &'a str,
861+
}
862+
854863
#[derive(Diagnostic)]
855864
#[diag(builtin_macros_test_runner_invalid)]
856865
pub(crate) struct TestRunnerInvalid {

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ fn const_validate_mplace<'tcx>(
396396
let alloc_id = mplace.ptr().provenance.unwrap().alloc_id();
397397
let mut ref_tracking = RefTracking::new(mplace.clone());
398398
let mut inner = false;
399-
while let Some((mplace, path)) = ref_tracking.todo.pop() {
399+
while let Some((mplace, path)) = ref_tracking.next() {
400400
let mode = match ecx.tcx.static_mutability(cid.instance.def_id()) {
401401
_ if cid.promoted.is_some() => CtfeValidationMode::Promoted,
402402
Some(mutbl) => CtfeValidationMode::Static { mutbl }, // a `static`

compiler/rustc_const_eval/src/interpret/machine.rs

+7
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,13 @@ pub trait Machine<'tcx>: Sized {
165165

166166
/// Whether to enforce the validity invariant for a specific layout.
167167
fn enforce_validity(ecx: &InterpCx<'tcx, Self>, layout: TyAndLayout<'tcx>) -> bool;
168+
/// Whether to enforce the validity invariant *recursively*.
169+
fn enforce_validity_recursively(
170+
_ecx: &InterpCx<'tcx, Self>,
171+
_layout: TyAndLayout<'tcx>,
172+
) -> bool {
173+
false
174+
}
168175

169176
/// Whether function calls should be [ABI](CallAbi)-checked.
170177
fn enforce_abi(_ecx: &InterpCx<'tcx, Self>) -> bool {

compiler/rustc_const_eval/src/interpret/memory.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1006,8 +1006,11 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
10061006
})
10071007
}
10081008

1009-
/// Runs the close in "validation" mode, which means the machine's memory read hooks will be
1009+
/// Runs the closure in "validation" mode, which means the machine's memory read hooks will be
10101010
/// suppressed. Needless to say, this must only be set with great care! Cannot be nested.
1011+
///
1012+
/// We do this so Miri's allocation access tracking does not show the validation
1013+
/// reads as spurious accesses.
10111014
pub(super) fn run_for_validation<R>(&self, f: impl FnOnce() -> R) -> R {
10121015
// This deliberately uses `==` on `bool` to follow the pattern
10131016
// `assert!(val.replace(new) == old)`.

compiler/rustc_const_eval/src/interpret/place.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,10 @@ where
572572

573573
if M::enforce_validity(self, dest.layout()) {
574574
// Data got changed, better make sure it matches the type!
575-
self.validate_operand(&dest.to_op(self)?)?;
575+
self.validate_operand(
576+
&dest.to_op(self)?,
577+
M::enforce_validity_recursively(self, dest.layout()),
578+
)?;
576579
}
577580

578581
Ok(())
@@ -811,15 +814,21 @@ where
811814
// Generally for transmutation, data must be valid both at the old and new type.
812815
// But if the types are the same, the 2nd validation below suffices.
813816
if src.layout().ty != dest.layout().ty && M::enforce_validity(self, src.layout()) {
814-
self.validate_operand(&src.to_op(self)?)?;
817+
self.validate_operand(
818+
&src.to_op(self)?,
819+
M::enforce_validity_recursively(self, src.layout()),
820+
)?;
815821
}
816822

817823
// Do the actual copy.
818824
self.copy_op_no_validate(src, dest, allow_transmute)?;
819825

820826
if validate_dest && M::enforce_validity(self, dest.layout()) {
821827
// Data got changed, better make sure it matches the type!
822-
self.validate_operand(&dest.to_op(self)?)?;
828+
self.validate_operand(
829+
&dest.to_op(self)?,
830+
M::enforce_validity_recursively(self, dest.layout()),
831+
)?;
823832
}
824833

825834
Ok(())

0 commit comments

Comments
 (0)