Skip to content

Commit 4493a0f

Browse files
committed
Auto merge of #100063 - matthiaskrgr:rollup-lznouys, r=matthiaskrgr
Rollup of 7 pull requests Successful merges: - #99987 (Always include a position span in `rustc_parse_format::Argument`) - #100005 (Remove Clean trait for ast::Attribute and improve Attributes::from_ast) - #100025 (Remove redundant `TransferWrapper` struct) - #100045 (Properly reject the `may_unwind` option in `global_asm!`) - #100052 (RISC-V ASM test: relax label name constraint.) - #100053 (move [`assertions_on_result_states`] to restriction) - #100057 (Remove more Clean trait implementations) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 06f4950 + 269d15f commit 4493a0f

File tree

23 files changed

+185
-150
lines changed

23 files changed

+185
-150
lines changed

compiler/rustc_builtin_macros/src/asm.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,12 @@ fn parse_options<'a>(
410410
try_set_option(p, args, sym::noreturn, ast::InlineAsmOptions::NORETURN);
411411
} else if !is_global_asm && p.eat_keyword(sym::nostack) {
412412
try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK);
413+
} else if !is_global_asm && p.eat_keyword(sym::may_unwind) {
414+
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
413415
} else if p.eat_keyword(sym::att_syntax) {
414416
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
415417
} else if p.eat_keyword(kw::Raw) {
416418
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW);
417-
} else if p.eat_keyword(sym::may_unwind) {
418-
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
419419
} else {
420420
return p.unexpected();
421421
}
@@ -656,7 +656,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
656656
let span = arg_spans.next().unwrap_or(template_sp);
657657

658658
let operand_idx = match arg.position {
659-
parse::ArgumentIs(idx, _) | parse::ArgumentImplicitlyIs(idx) => {
659+
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
660660
if idx >= args.operands.len()
661661
|| named_pos.contains_key(&idx)
662662
|| args.reg_args.contains(&idx)
@@ -702,11 +702,12 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
702702
Some(idx)
703703
}
704704
}
705-
parse::ArgumentNamed(name, span) => {
705+
parse::ArgumentNamed(name) => {
706706
match args.named_args.get(&Symbol::intern(name)) {
707707
Some(&idx) => Some(idx),
708708
None => {
709709
let msg = format!("there is no argument named `{}`", name);
710+
let span = arg.position_span;
710711
ecx.struct_span_err(
711712
template_span
712713
.from_inner(InnerSpan::new(span.start, span.end)),

compiler/rustc_builtin_macros/src/format.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,8 @@ impl<'a, 'b> Context<'a, 'b> {
381381
match *p {
382382
parse::String(_) => {}
383383
parse::NextArgument(ref mut arg) => {
384-
if let parse::ArgumentNamed(s, _) = arg.position {
385-
arg.position = parse::ArgumentIs(lookup(s), None);
384+
if let parse::ArgumentNamed(s) = arg.position {
385+
arg.position = parse::ArgumentIs(lookup(s));
386386
}
387387
if let parse::CountIsName(s, _) = arg.format.width {
388388
arg.format.width = parse::CountIsParam(lookup(s));
@@ -417,14 +417,14 @@ impl<'a, 'b> Context<'a, 'b> {
417417
// argument second, if it's an implicit positional parameter
418418
// it's written second, so it should come after width/precision.
419419
let pos = match arg.position {
420-
parse::ArgumentIs(i, arg_end) => {
420+
parse::ArgumentIs(i) => {
421421
self.unused_names_lint.maybe_add_positional_named_arg(
422422
i,
423423
self.args.len(),
424424
i,
425425
PositionalNamedArgType::Arg,
426426
self.curpiece,
427-
arg_end,
427+
Some(arg.position_span),
428428
&self.names,
429429
);
430430

@@ -442,8 +442,9 @@ impl<'a, 'b> Context<'a, 'b> {
442442
);
443443
Exact(i)
444444
}
445-
parse::ArgumentNamed(s, span) => {
445+
parse::ArgumentNamed(s) => {
446446
let symbol = Symbol::intern(s);
447+
let span = arg.position_span;
447448
Named(symbol, InnerSpan::new(span.start, span.end))
448449
}
449450
};
@@ -878,8 +879,9 @@ impl<'a, 'b> Context<'a, 'b> {
878879
// track the current argument ourselves.
879880
let i = self.curarg;
880881
self.curarg += 1;
881-
parse::ArgumentIs(i, None)
882+
parse::ArgumentIs(i)
882883
},
884+
position_span: arg.position_span,
883885
format: parse::FormatSpec {
884886
fill: arg.format.fill,
885887
align: parse::AlignUnknown,

compiler/rustc_mir_dataflow/src/impls/liveness.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,6 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> {
222222
}
223223
}
224224

225-
struct TransferWrapper<'a>(&'a mut ChunkedBitSet<Local>);
226-
227-
impl<'a> GenKill<Local> for TransferWrapper<'a> {
228-
fn gen(&mut self, l: Local) {
229-
self.0.insert(l);
230-
}
231-
232-
fn kill(&mut self, l: Local) {
233-
self.0.remove(l);
234-
}
235-
}
236-
237225
impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
238226
fn apply_statement_effect(
239227
&self,
@@ -271,7 +259,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
271259
return;
272260
}
273261
}
274-
TransferFunction(&mut TransferWrapper(trans)).visit_statement(statement, location);
262+
TransferFunction(trans).visit_statement(statement, location);
275263
}
276264

277265
fn apply_terminator_effect(
@@ -280,7 +268,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
280268
terminator: &mir::Terminator<'tcx>,
281269
location: Location,
282270
) {
283-
TransferFunction(&mut TransferWrapper(trans)).visit_terminator(terminator, location);
271+
TransferFunction(trans).visit_terminator(terminator, location);
284272
}
285273

286274
fn apply_call_return_effect(

compiler/rustc_parse_format/src/lib.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ pub enum Piece<'a> {
7070
pub struct Argument<'a> {
7171
/// Where to find this argument
7272
pub position: Position<'a>,
73+
/// The span of the position indicator. Includes any whitespace in implicit
74+
/// positions (`{ }`).
75+
pub position_span: InnerSpan,
7376
/// How to format the argument
7477
pub format: FormatSpec<'a>,
7578
}
@@ -105,9 +108,9 @@ pub enum Position<'a> {
105108
/// The argument is implied to be located at an index
106109
ArgumentImplicitlyIs(usize),
107110
/// The argument is located at a specific index given in the format,
108-
ArgumentIs(usize, Option<InnerSpan>),
111+
ArgumentIs(usize),
109112
/// The argument has a name.
110-
ArgumentNamed(&'a str, InnerSpan),
113+
ArgumentNamed(&'a str),
111114
}
112115

113116
impl Position<'_> {
@@ -216,14 +219,15 @@ impl<'a> Iterator for Parser<'a> {
216219
'{' => {
217220
let curr_last_brace = self.last_opening_brace;
218221
let byte_pos = self.to_span_index(pos);
219-
self.last_opening_brace = Some(byte_pos.to(InnerOffset(byte_pos.0 + 1)));
222+
let lbrace_end = InnerOffset(byte_pos.0 + 1);
223+
self.last_opening_brace = Some(byte_pos.to(lbrace_end));
220224
self.cur.next();
221225
if self.consume('{') {
222226
self.last_opening_brace = curr_last_brace;
223227

224228
Some(String(self.string(pos + 1)))
225229
} else {
226-
let arg = self.argument();
230+
let arg = self.argument(lbrace_end);
227231
if let Some(rbrace_byte_idx) = self.must_consume('}') {
228232
let lbrace_inner_offset = self.to_span_index(pos);
229233
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
@@ -477,8 +481,16 @@ impl<'a> Parser<'a> {
477481
}
478482

479483
/// Parses an `Argument` structure, or what's contained within braces inside the format string.
480-
fn argument(&mut self) -> Argument<'a> {
484+
fn argument(&mut self, start: InnerOffset) -> Argument<'a> {
481485
let pos = self.position();
486+
487+
let end = self
488+
.cur
489+
.clone()
490+
.find(|(_, ch)| !ch.is_whitespace())
491+
.map_or(start, |(end, _)| self.to_span_index(end));
492+
let position_span = start.to(end);
493+
482494
let format = match self.mode {
483495
ParseMode::Format => self.format(),
484496
ParseMode::InlineAsm => self.inline_asm(),
@@ -494,31 +506,19 @@ impl<'a> Parser<'a> {
494506
}
495507
};
496508

497-
Argument { position: pos, format }
509+
Argument { position: pos, position_span, format }
498510
}
499511

500512
/// Parses a positional argument for a format. This could either be an
501513
/// integer index of an argument, a named argument, or a blank string.
502514
/// Returns `Some(parsed_position)` if the position is not implicitly
503515
/// consuming a macro argument, `None` if it's the case.
504516
fn position(&mut self) -> Option<Position<'a>> {
505-
let start_position = self.cur.peek().map(|item| item.0);
506517
if let Some(i) = self.integer() {
507-
let inner_span = start_position.and_then(|start| {
508-
self.cur
509-
.peek()
510-
.cloned()
511-
.and_then(|item| Some(self.to_span_index(start).to(self.to_span_index(item.0))))
512-
});
513-
Some(ArgumentIs(i, inner_span))
518+
Some(ArgumentIs(i))
514519
} else {
515520
match self.cur.peek() {
516-
Some(&(start, c)) if rustc_lexer::is_id_start(c) => {
517-
let word = self.word();
518-
let end = start + word.len();
519-
let span = self.to_span_index(start).to(self.to_span_index(end));
520-
Some(ArgumentNamed(word, span))
521-
}
521+
Some(&(_, c)) if rustc_lexer::is_id_start(c) => Some(ArgumentNamed(self.word())),
522522

523523
// This is an `ArgumentNext`.
524524
// Record the fact and do the resolution after parsing the

0 commit comments

Comments
 (0)