Skip to content

Commit 128417f

Browse files
committed
Auto merge of rust-lang#92996 - matthiaskrgr:rollup-50wpzva, r=matthiaskrgr
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
2 parents fd20513 + 9612038 commit 128417f

29 files changed

+416
-253
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -4443,6 +4443,7 @@ version = "0.0.0"
44434443
dependencies = [
44444444
"arrayvec",
44454445
"askama",
4446+
"atty",
44464447
"expect-test",
44474448
"itertools 0.9.0",
44484449
"minifier",

compiler/rustc_ast_pretty/src/pp.rs

+23-23
Original file line numberDiff line numberDiff line change
@@ -222,29 +222,6 @@ struct PrintStackElem {
222222

223223
const SIZE_INFINITY: isize = 0xffff;
224224

225-
pub fn mk_printer() -> Printer {
226-
let linewidth = 78;
227-
// Yes 55, it makes the ring buffers big enough to never fall behind.
228-
let n: usize = 55 * linewidth;
229-
debug!("mk_printer {}", linewidth);
230-
Printer {
231-
out: String::new(),
232-
buf_max_len: n,
233-
margin: linewidth as isize,
234-
space: linewidth as isize,
235-
left: 0,
236-
right: 0,
237-
// Initialize a single entry; advance_right() will extend it on demand
238-
// up to `buf_max_len` elements.
239-
buf: vec![BufEntry::default()],
240-
left_total: 0,
241-
right_total: 0,
242-
scan_stack: VecDeque::new(),
243-
print_stack: Vec::new(),
244-
pending_indentation: 0,
245-
}
246-
}
247-
248225
pub struct Printer {
249226
out: String,
250227
buf_max_len: usize,
@@ -288,6 +265,29 @@ impl Default for BufEntry {
288265
}
289266

290267
impl Printer {
268+
pub fn new() -> Self {
269+
let linewidth = 78;
270+
// Yes 55, it makes the ring buffers big enough to never fall behind.
271+
let n: usize = 55 * linewidth;
272+
debug!("Printer::new {}", linewidth);
273+
Printer {
274+
out: String::new(),
275+
buf_max_len: n,
276+
margin: linewidth as isize,
277+
space: linewidth as isize,
278+
left: 0,
279+
right: 0,
280+
// Initialize a single entry; advance_right() will extend it on demand
281+
// up to `buf_max_len` elements.
282+
buf: vec![BufEntry::default()],
283+
left_total: 0,
284+
right_total: 0,
285+
scan_stack: VecDeque::new(),
286+
print_stack: Vec::new(),
287+
pending_indentation: 0,
288+
}
289+
}
290+
291291
pub fn last_token(&self) -> Token {
292292
self.buf[self.right].token.clone()
293293
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn print_crate<'a>(
103103
edition: Edition,
104104
) -> String {
105105
let mut s =
106-
State { s: pp::mk_printer(), comments: Some(Comments::new(sm, filename, input)), ann };
106+
State { s: pp::Printer::new(), comments: Some(Comments::new(sm, filename, input)), ann };
107107

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

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

916916
crate fn commasep_cmnt<T, F, G>(&mut self, b: Breaks, elts: &[T], mut op: F, mut get_span: G)

compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl<'a> State<'a> {
170170
ann: &'a dyn PpAnn,
171171
) -> State<'a> {
172172
State {
173-
s: pp::mk_printer(),
173+
s: pp::Printer::new(),
174174
comments: Some(Comments::new(sm, filename, input)),
175175
attrs,
176176
ann,
@@ -186,7 +186,7 @@ pub fn to_string<F>(ann: &dyn PpAnn, f: F) -> String
186186
where
187187
F: FnOnce(&mut State<'_>),
188188
{
189-
let mut printer = State { s: pp::mk_printer(), comments: None, attrs: &|_| &[], ann };
189+
let mut printer = State { s: pp::Printer::new(), comments: None, attrs: &|_| &[], ann };
190190
f(&mut printer);
191191
printer.s.eof()
192192
}

compiler/rustc_parse/src/parser/diagnostics.rs

+23-16
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use std::mem::take;
2727
use tracing::{debug, trace};
2828

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

3232
/// Creates a placeholder argument.
3333
pub(super) fn dummy_arg(ident: Ident) -> Param {
@@ -731,21 +731,28 @@ impl<'a> Parser<'a> {
731731
match x {
732732
Ok((_, _, false)) => {
733733
if self.eat(&token::Gt) {
734-
match self.parse_expr() {
735-
Ok(_) => {
736-
e.span_suggestion_verbose(
737-
binop.span.shrink_to_lo(),
738-
TURBOFISH_SUGGESTION_STR,
739-
"::".to_string(),
740-
Applicability::MaybeIncorrect,
741-
);
742-
e.emit();
743-
*expr =
744-
self.mk_expr_err(expr.span.to(self.prev_token.span));
745-
return Ok(());
746-
}
747-
Err(mut err) => {
748-
err.cancel();
734+
let turbo_err = e.span_suggestion_verbose(
735+
binop.span.shrink_to_lo(),
736+
TURBOFISH_SUGGESTION_STR,
737+
"::".to_string(),
738+
Applicability::MaybeIncorrect,
739+
);
740+
if self.check(&TokenKind::Semi) {
741+
turbo_err.emit();
742+
*expr = self.mk_expr_err(expr.span);
743+
return Ok(());
744+
} else {
745+
match self.parse_expr() {
746+
Ok(_) => {
747+
turbo_err.emit();
748+
*expr = self
749+
.mk_expr_err(expr.span.to(self.prev_token.span));
750+
return Ok(());
751+
}
752+
Err(mut err) => {
753+
turbo_err.cancel();
754+
err.cancel();
755+
}
749756
}
750757
}
751758
}

compiler/rustc_parse/src/parser/expr.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1443,7 +1443,7 @@ impl<'a> Parser<'a> {
14431443
&mut self,
14441444
label: Label,
14451445
attrs: AttrVec,
1446-
consume_colon: bool,
1446+
mut consume_colon: bool,
14471447
) -> PResult<'a, P<Expr>> {
14481448
let lo = label.ident.span;
14491449
let label = Some(label);
@@ -1456,6 +1456,12 @@ impl<'a> Parser<'a> {
14561456
self.parse_loop_expr(label, lo, attrs)
14571457
} else if self.check(&token::OpenDelim(token::Brace)) || self.token.is_whole_block() {
14581458
self.parse_block_expr(label, lo, BlockCheckMode::Default, attrs)
1459+
} else if !ate_colon && (self.check(&TokenKind::Comma) || self.check(&TokenKind::Gt)) {
1460+
// We're probably inside of a `Path<'a>` that needs a turbofish, so suppress the
1461+
// "must be followed by a colon" error.
1462+
self.diagnostic().delay_span_bug(lo, "this label wasn't parsed correctly");
1463+
consume_colon = false;
1464+
Ok(self.mk_expr_err(lo))
14591465
} else {
14601466
let msg = "expected `while`, `for`, `loop` or `{` after a label";
14611467
self.struct_span_err(self.token.span, msg).span_label(self.token.span, msg).emit();

0 commit comments

Comments
 (0)