Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 10 pull requests #92996

Merged
merged 24 commits into from
Jan 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c84f2b2
Remove some unnecessary uses of `FieldDef::ident`
camelid Jan 12, 2022
51d7665
rustdoc: remove hand-rolled isatty
euclio Jan 12, 2022
867554a
Fix suggesting turbofish with lifetime arguments
compiler-errors Jan 13, 2022
7781636
Link sidebar "location" heading to top of page
jsha Jan 11, 2022
dae6dc6
Fix `try wrapping expression in variant` suggestion with struct field…
compiler-errors Jan 12, 2022
272fb23
Don't use source-map when detecting struct field shorthand
compiler-errors Jan 13, 2022
953da98
Rename Printer constructor from mk_printer() to Printer::new()
dtolnay Jan 15, 2022
29b659a
Fix missing dot separator
GuillaumeGomez Jan 15, 2022
75967ce
Add test for dot separator
GuillaumeGomez Jan 15, 2022
8f33b4e
Copy an example to PartialOrd as well
azdavis Jan 16, 2022
828febf
Clear up discriminants with more examples
azdavis Jan 16, 2022
bfe0a4e
Touch up stray comment in PR 92953
dtolnay Jan 16, 2022
361ef2a
Docs: recommend VecDeque instead of Vec::remove(0)
kornelski Jan 16, 2022
bb1423e
fix const_ptr_offset_from tracking issue
RalfJung Jan 16, 2022
869b7bc
Rollup merge of #92795 - jsha:link-to-top, r=GuillaumeGomez
matthiaskrgr Jan 17, 2022
3de7276
Rollup merge of #92799 - rust-lang:followup-from-92533, r=Aaron1011
matthiaskrgr Jan 17, 2022
ff1b653
Rollup merge of #92808 - compiler-errors:wrap-struct-shorthand-field-…
matthiaskrgr Jan 17, 2022
681271e
Rollup merge of #92819 - euclio:atty, r=CraftSpider
matthiaskrgr Jan 17, 2022
c6ff4be
Rollup merge of #92876 - compiler-errors:fix-turbofish-lifetime-sugge…
matthiaskrgr Jan 17, 2022
216ce7c
Rollup merge of #92921 - dtolnay:printernew, r=wesleywiser
matthiaskrgr Jan 17, 2022
0aae1ec
Rollup merge of #92937 - GuillaumeGomez:dot-separator, r=jsha
matthiaskrgr Jan 17, 2022
775fe37
Rollup merge of #92953 - azdavis:azdavis-copy-example, r=dtolnay
matthiaskrgr Jan 17, 2022
7bdd978
Rollup merge of #92977 - kornelski:popdoc, r=dtolnay
matthiaskrgr Jan 17, 2022
9612038
Rollup merge of #92981 - RalfJung:const_ptr_offset_from, r=dtolnay
matthiaskrgr Jan 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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