Skip to content

Commit

Permalink
Auto merge of rust-lang#92996 - matthiaskrgr:rollup-50wpzva, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 10 pull requests

Successful merges:

 - rust-lang#92795 (Link sidebar "location" heading to top of page)
 - rust-lang#92799 (Remove some unnecessary uses of `FieldDef::ident`)
 - rust-lang#92808 (Fix `try wrapping expression in variant` suggestion with struct field shorthand)
 - rust-lang#92819 (rustdoc: remove hand-rolled isatty)
 - rust-lang#92876 (Fix suggesting turbofish with lifetime arguments)
 - rust-lang#92921 (Rename Printer constructor from mk_printer() to Printer::new())
 - rust-lang#92937 (rustdoc: Add missing dot separator)
 - rust-lang#92953 (Copy an example to PartialOrd as well)
 - rust-lang#92977 (Docs: recommend VecDeque instead of Vec::remove(0))
 - rust-lang#92981 (fix const_ptr_offset_from tracking issue)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Jan 17, 2022
2 parents fd20513 + 9612038 commit 128417f
Show file tree
Hide file tree
Showing 29 changed files with 416 additions and 253 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4443,6 +4443,7 @@ version = "0.0.0"
dependencies = [
"arrayvec",
"askama",
"atty",
"expect-test",
"itertools 0.9.0",
"minifier",
Expand Down
46 changes: 23 additions & 23 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,29 +222,6 @@ struct PrintStackElem {

const SIZE_INFINITY: isize = 0xffff;

pub fn mk_printer() -> Printer {
let linewidth = 78;
// Yes 55, it makes the ring buffers big enough to never fall behind.
let n: usize = 55 * linewidth;
debug!("mk_printer {}", linewidth);
Printer {
out: String::new(),
buf_max_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
// Initialize a single entry; advance_right() will extend it on demand
// up to `buf_max_len` elements.
buf: vec![BufEntry::default()],
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
print_stack: Vec::new(),
pending_indentation: 0,
}
}

pub struct Printer {
out: String,
buf_max_len: usize,
Expand Down Expand Up @@ -288,6 +265,29 @@ impl Default for BufEntry {
}

impl Printer {
pub fn new() -> Self {
let linewidth = 78;
// Yes 55, it makes the ring buffers big enough to never fall behind.
let n: usize = 55 * linewidth;
debug!("Printer::new {}", linewidth);
Printer {
out: String::new(),
buf_max_len: n,
margin: linewidth as isize,
space: linewidth as isize,
left: 0,
right: 0,
// Initialize a single entry; advance_right() will extend it on demand
// up to `buf_max_len` elements.
buf: vec![BufEntry::default()],
left_total: 0,
right_total: 0,
scan_stack: VecDeque::new(),
print_stack: Vec::new(),
pending_indentation: 0,
}
}

pub fn last_token(&self) -> Token {
self.buf[self.right].token.clone()
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub fn print_crate<'a>(
edition: Edition,
) -> String {
let mut s =
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann };
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };

if is_expanded && !krate.attrs.iter().any(|attr| attr.has_name(sym::no_core)) {
// We need to print `#![no_std]` (and its feature gate) so that
Expand Down Expand Up @@ -910,7 +910,7 @@ impl<'a> PrintState<'a> for State<'a> {

impl<'a> State<'a> {
pub fn new() -> State<'a> {
State { s: pp::mk_printer(), comments: None, ann: &NoAnn }
State { s: pp::Printer::new(), comments: None, ann: &NoAnn }
}

crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl<'a> State<'a> {
ann: &'a dyn PpAnn,
) -> State<'a> {
State {
s: pp::mk_printer(),
s: pp::Printer::new(),
comments: Some(Comments::new(sm, filename, input)),
attrs,
ann,
Expand All @@ -186,7 +186,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
where
F: FnOnce(&mut State<'_>),
{
let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
let mut printer = State { s: pp::Printer::new(), comments: None, attrs: &|_| &[], ann };
f(&mut printer);
printer.s.eof()
}
Expand Down
39 changes: 23 additions & 16 deletions compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use std::mem::take;
use tracing::{debug, trace};

const TURBOFISH_SUGGESTION_STR: &str =
"use `::<...>` instead of `<...>` to specify type or const arguments";
"use `::<...>` instead of `<...>` to specify lifetime, type, or const arguments";

/// Creates a placeholder argument.
pub(super) fn dummy_arg(ident: Ident) -> Param {
Expand Down Expand Up @@ -731,21 +731,28 @@ impl<'a> Parser<'a> {
match x {
Ok((_, _, false)) => {
if self.eat(&token::Gt) {
match self.parse_expr() {
Ok(_) => {
e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
e.emit();
*expr =
self.mk_expr_err(expr.span.to(self.prev_token.span));
return Ok(());
}
Err(mut err) => {
err.cancel();
let turbo_err = e.span_suggestion_verbose(
binop.span.shrink_to_lo(),
TURBOFISH_SUGGESTION_STR,
"::".to_string(),
Applicability::MaybeIncorrect,
);
if self.check(&TokenKind::Semi) {
turbo_err.emit();
*expr = self.mk_expr_err(expr.span);
return Ok(());
} else {
match self.parse_expr() {
Ok(_) => {
turbo_err.emit();
*expr = self
.mk_expr_err(expr.span.to(self.prev_token.span));
return Ok(());
}
Err(mut err) => {
turbo_err.cancel();
err.cancel();
}
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ impl<'a> Parser<'a> {
&mut self,
label: Label,
attrs: AttrVec,
consume_colon: bool,
mut consume_colon: bool,
) -> PResult<'a, P<Expr>> {
let lo = label.ident.span;
let label = Some(label);
Expand All @@ -1456,6 +1456,12 @@ impl<'a> Parser<'a> {
self.parse_loop_expr(label, lo, attrs)
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
// "must be followed by a colon" error.
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
consume_colon = false;
Ok(self.mk_expr_err(lo))
} else {
let msg = "expected `while`, `for`, `loop` or `{` after a label";
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();
Expand Down
Loading

0 comments on commit 128417f

Please sign in to comment.