Skip to content

Commit

Permalink
Auto merge of rust-lang#100063 - matthiaskrgr:rollup-lznouys, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#99987 (Always include a position span in `rustc_parse_format::Argument`)
 - rust-lang#100005 (Remove Clean trait for ast::Attribute and improve Attributes::from_ast)
 - rust-lang#100025 (Remove redundant `TransferWrapper` struct)
 - rust-lang#100045 (Properly reject the `may_unwind` option in `global_asm!`)
 - rust-lang#100052 (RISC-V ASM test: relax label name constraint.)
 - rust-lang#100053 (move [`assertions_on_result_states`] to restriction)
 - rust-lang#100057 (Remove more Clean trait implementations)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Aug 2, 2022
2 parents 06f4950 + 269d15f commit 4493a0f
Show file tree
Hide file tree
Showing 23 changed files with 185 additions and 150 deletions.
9 changes: 5 additions & 4 deletions compiler/rustc_builtin_macros/src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,12 +410,12 @@ fn parse_options<'a>(
try_set_option(p, args, sym::noreturn, ast::InlineAsmOptions::NORETURN);
} else if !is_global_asm && p.eat_keyword(sym::nostack) {
try_set_option(p, args, sym::nostack, ast::InlineAsmOptions::NOSTACK);
} else if !is_global_asm && p.eat_keyword(sym::may_unwind) {
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
} else if p.eat_keyword(sym::att_syntax) {
try_set_option(p, args, sym::att_syntax, ast::InlineAsmOptions::ATT_SYNTAX);
} else if p.eat_keyword(kw::Raw) {
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::RAW);
} else if p.eat_keyword(sym::may_unwind) {
try_set_option(p, args, kw::Raw, ast::InlineAsmOptions::MAY_UNWIND);
} else {
return p.unexpected();
}
Expand Down Expand Up @@ -656,7 +656,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
let span = arg_spans.next().unwrap_or(template_sp);

let operand_idx = match arg.position {
parse::ArgumentIs(idx, _) | parse::ArgumentImplicitlyIs(idx) => {
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
if idx >= args.operands.len()
|| named_pos.contains_key(&idx)
|| args.reg_args.contains(&idx)
Expand Down Expand Up @@ -702,11 +702,12 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
Some(idx)
}
}
parse::ArgumentNamed(name, span) => {
parse::ArgumentNamed(name) => {
match args.named_args.get(&Symbol::intern(name)) {
Some(&idx) => Some(idx),
None => {
let msg = format!("there is no argument named `{}`", name);
let span = arg.position_span;
ecx.struct_span_err(
template_span
.from_inner(InnerSpan::new(span.start, span.end)),
Expand Down
14 changes: 8 additions & 6 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,8 +381,8 @@ impl<'a, 'b> Context<'a, 'b> {
match *p {
parse::String(_) => {}
parse::NextArgument(ref mut arg) => {
if let parse::ArgumentNamed(s, _) = arg.position {
arg.position = parse::ArgumentIs(lookup(s), None);
if let parse::ArgumentNamed(s) = arg.position {
arg.position = parse::ArgumentIs(lookup(s));
}
if let parse::CountIsName(s, _) = arg.format.width {
arg.format.width = parse::CountIsParam(lookup(s));
Expand Down Expand Up @@ -417,14 +417,14 @@ impl<'a, 'b> Context<'a, 'b> {
// argument second, if it's an implicit positional parameter
// it's written second, so it should come after width/precision.
let pos = match arg.position {
parse::ArgumentIs(i, arg_end) => {
parse::ArgumentIs(i) => {
self.unused_names_lint.maybe_add_positional_named_arg(
i,
self.args.len(),
i,
PositionalNamedArgType::Arg,
self.curpiece,
arg_end,
Some(arg.position_span),
&self.names,
);

Expand All @@ -442,8 +442,9 @@ impl<'a, 'b> Context<'a, 'b> {
);
Exact(i)
}
parse::ArgumentNamed(s, span) => {
parse::ArgumentNamed(s) => {
let symbol = Symbol::intern(s);
let span = arg.position_span;
Named(symbol, InnerSpan::new(span.start, span.end))
}
};
Expand Down Expand Up @@ -878,8 +879,9 @@ impl<'a, 'b> Context<'a, 'b> {
// track the current argument ourselves.
let i = self.curarg;
self.curarg += 1;
parse::ArgumentIs(i, None)
parse::ArgumentIs(i)
},
position_span: arg.position_span,
format: parse::FormatSpec {
fill: arg.format.fill,
align: parse::AlignUnknown,
Expand Down
16 changes: 2 additions & 14 deletions compiler/rustc_mir_dataflow/src/impls/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,18 +222,6 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for MaybeTransitiveLiveLocals<'a> {
}
}

struct TransferWrapper<'a>(&'a mut ChunkedBitSet<Local>);

impl<'a> GenKill<Local> for TransferWrapper<'a> {
fn gen(&mut self, l: Local) {
self.0.insert(l);
}

fn kill(&mut self, l: Local) {
self.0.remove(l);
}
}

impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
fn apply_statement_effect(
&self,
Expand Down Expand Up @@ -271,7 +259,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
return;
}
}
TransferFunction(&mut TransferWrapper(trans)).visit_statement(statement, location);
TransferFunction(trans).visit_statement(statement, location);
}

fn apply_terminator_effect(
Expand All @@ -280,7 +268,7 @@ impl<'a, 'tcx> Analysis<'tcx> for MaybeTransitiveLiveLocals<'a> {
terminator: &mir::Terminator<'tcx>,
location: Location,
) {
TransferFunction(&mut TransferWrapper(trans)).visit_terminator(terminator, location);
TransferFunction(trans).visit_terminator(terminator, location);
}

fn apply_call_return_effect(
Expand Down
40 changes: 20 additions & 20 deletions compiler/rustc_parse_format/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ pub enum Piece<'a> {
pub struct Argument<'a> {
/// Where to find this argument
pub position: Position<'a>,
/// The span of the position indicator. Includes any whitespace in implicit
/// positions (`{ }`).
pub position_span: InnerSpan,
/// How to format the argument
pub format: FormatSpec<'a>,
}
Expand Down Expand Up @@ -105,9 +108,9 @@ pub enum Position<'a> {
/// The argument is implied to be located at an index
ArgumentImplicitlyIs(usize),
/// The argument is located at a specific index given in the format,
ArgumentIs(usize, Option<InnerSpan>),
ArgumentIs(usize),
/// The argument has a name.
ArgumentNamed(&'a str, InnerSpan),
ArgumentNamed(&'a str),
}

impl Position<'_> {
Expand Down Expand Up @@ -216,14 +219,15 @@ impl<'a> Iterator for Parser<'a> {
'{' => {
let curr_last_brace = self.last_opening_brace;
let byte_pos = self.to_span_index(pos);
self.last_opening_brace = Some(byte_pos.to(InnerOffset(byte_pos.0 + 1)));
let lbrace_end = InnerOffset(byte_pos.0 + 1);
self.last_opening_brace = Some(byte_pos.to(lbrace_end));
self.cur.next();
if self.consume('{') {
self.last_opening_brace = curr_last_brace;

Some(String(self.string(pos + 1)))
} else {
let arg = self.argument();
let arg = self.argument(lbrace_end);
if let Some(rbrace_byte_idx) = self.must_consume('}') {
let lbrace_inner_offset = self.to_span_index(pos);
let rbrace_inner_offset = self.to_span_index(rbrace_byte_idx);
Expand Down Expand Up @@ -477,8 +481,16 @@ impl<'a> Parser<'a> {
}

/// Parses an `Argument` structure, or what's contained within braces inside the format string.
fn argument(&mut self) -> Argument<'a> {
fn argument(&mut self, start: InnerOffset) -> Argument<'a> {
let pos = self.position();

let end = self
.cur
.clone()
.find(|(_, ch)| !ch.is_whitespace())
.map_or(start, |(end, _)| self.to_span_index(end));
let position_span = start.to(end);

let format = match self.mode {
ParseMode::Format => self.format(),
ParseMode::InlineAsm => self.inline_asm(),
Expand All @@ -494,31 +506,19 @@ impl<'a> Parser<'a> {
}
};

Argument { position: pos, format }
Argument { position: pos, position_span, format }
}

/// Parses a positional argument for a format. This could either be an
/// integer index of an argument, a named argument, or a blank string.
/// Returns `Some(parsed_position)` if the position is not implicitly
/// consuming a macro argument, `None` if it's the case.
fn position(&mut self) -> Option<Position<'a>> {
let start_position = self.cur.peek().map(|item| item.0);
if let Some(i) = self.integer() {
let inner_span = start_position.and_then(|start| {
self.cur
.peek()
.cloned()
.and_then(|item| Some(self.to_span_index(start).to(self.to_span_index(item.0))))
});
Some(ArgumentIs(i, inner_span))
Some(ArgumentIs(i))
} else {
match self.cur.peek() {
Some(&(start, c)) if rustc_lexer::is_id_start(c) => {
let word = self.word();
let end = start + word.len();
let span = self.to_span_index(start).to(self.to_span_index(end));
Some(ArgumentNamed(word, span))
}
Some(&(_, c)) if rustc_lexer::is_id_start(c) => Some(ArgumentNamed(self.word())),

// This is an `ArgumentNext`.
// Record the fact and do the resolution after parsing the
Expand Down
Loading

0 comments on commit 4493a0f

Please sign in to comment.