Skip to content

Commit 86f5e17

Browse files
committed
Auto merge of #93498 - matthiaskrgr:rollup-k5shwrc, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #90277 (Improve terminology around "after typeck") - #92918 (Allow eliding GATs in expression position) - #93039 (Don't suggest inaccessible fields) - #93155 (Switch pretty printer to block-based indentation) - #93214 (Respect doc(hidden) when suggesting available fields) - #93347 (Make `char::DecodeUtf16::size_hist` more precise) - #93392 (Clarify documentation on char::MAX) - #93444 (Fix some CSS warnings and errors from VS Code) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 415c9f9 + 2070b22 commit 86f5e17

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+593
-323
lines changed

compiler/rustc_ast_pretty/src/pp.rs

+49-20
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,22 @@ pub enum Breaks {
146146
Inconsistent,
147147
}
148148

149+
#[derive(Clone, Copy)]
150+
enum IndentStyle {
151+
/// Vertically aligned under whatever column this block begins at.
152+
///
153+
/// fn demo(arg1: usize,
154+
/// arg2: usize);
155+
Visual,
156+
/// Indented relative to the indentation level of the previous line.
157+
///
158+
/// fn demo(
159+
/// arg1: usize,
160+
/// arg2: usize,
161+
/// );
162+
Block { offset: isize },
163+
}
164+
149165
#[derive(Clone, Copy)]
150166
pub struct BreakToken {
151167
offset: isize,
@@ -154,7 +170,7 @@ pub struct BreakToken {
154170

155171
#[derive(Clone, Copy)]
156172
pub struct BeginToken {
157-
offset: isize,
173+
indent: IndentStyle,
158174
breaks: Breaks,
159175
}
160176

@@ -178,7 +194,7 @@ impl Token {
178194
#[derive(Copy, Clone)]
179195
enum PrintFrame {
180196
Fits,
181-
Broken { offset: isize, breaks: Breaks },
197+
Broken { indent: usize, breaks: Breaks },
182198
}
183199

184200
const SIZE_INFINITY: isize = 0xffff;
@@ -204,6 +220,8 @@ pub struct Printer {
204220
scan_stack: VecDeque<usize>,
205221
/// Stack of blocks-in-progress being flushed by print
206222
print_stack: Vec<PrintFrame>,
223+
/// Level of indentation of current line
224+
indent: usize,
207225
/// Buffered indentation to avoid writing trailing whitespace
208226
pending_indentation: isize,
209227
/// The token most recently popped from the left boundary of the
@@ -229,6 +247,7 @@ impl Printer {
229247
right_total: 0,
230248
scan_stack: VecDeque::new(),
231249
print_stack: Vec::new(),
250+
indent: 0,
232251
pending_indentation: 0,
233252
last_printed: None,
234253
}
@@ -368,38 +387,41 @@ impl Printer {
368387
*self
369388
.print_stack
370389
.last()
371-
.unwrap_or(&PrintFrame::Broken { offset: 0, breaks: Breaks::Inconsistent })
390+
.unwrap_or(&PrintFrame::Broken { indent: 0, breaks: Breaks::Inconsistent })
372391
}
373392

374393
fn print_begin(&mut self, token: BeginToken, size: isize) {
375394
if size > self.space {
376-
let col = self.margin - self.space + token.offset;
377-
self.print_stack.push(PrintFrame::Broken { offset: col, breaks: token.breaks });
395+
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
396+
self.indent = match token.indent {
397+
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
398+
IndentStyle::Visual => (self.margin - self.space) as usize,
399+
};
378400
} else {
379401
self.print_stack.push(PrintFrame::Fits);
380402
}
381403
}
382404

383405
fn print_end(&mut self) {
384-
self.print_stack.pop().unwrap();
406+
if let PrintFrame::Broken { indent, .. } = self.print_stack.pop().unwrap() {
407+
self.indent = indent;
408+
}
385409
}
386410

387411
fn print_break(&mut self, token: BreakToken, size: isize) {
388-
let break_offset =
389-
match self.get_top() {
390-
PrintFrame::Fits => None,
391-
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => Some(offset),
392-
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
393-
if size > self.space { Some(offset) } else { None }
394-
}
395-
};
396-
if let Some(offset) = break_offset {
397-
self.out.push('\n');
398-
self.pending_indentation = offset + token.offset;
399-
self.space = self.margin - (offset + token.offset);
400-
} else {
412+
let fits = match self.get_top() {
413+
PrintFrame::Fits => true,
414+
PrintFrame::Broken { breaks: Breaks::Consistent, .. } => false,
415+
PrintFrame::Broken { breaks: Breaks::Inconsistent, .. } => size <= self.space,
416+
};
417+
if fits {
401418
self.pending_indentation += token.blank_space;
402419
self.space -= token.blank_space;
420+
} else {
421+
self.out.push('\n');
422+
let indent = self.indent as isize + token.offset;
423+
self.pending_indentation = indent;
424+
self.space = self.margin - indent;
403425
}
404426
}
405427

@@ -422,7 +444,10 @@ impl Printer {
422444

423445
/// "raw box"
424446
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
425-
self.scan_begin(BeginToken { offset: indent as isize, breaks })
447+
self.scan_begin(BeginToken {
448+
indent: IndentStyle::Block { offset: indent as isize },
449+
breaks,
450+
})
426451
}
427452

428453
/// Inconsistent breaking box
@@ -435,6 +460,10 @@ impl Printer {
435460
self.rbox(indent, Breaks::Consistent)
436461
}
437462

463+
pub fn visual_align(&mut self) {
464+
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent });
465+
}
466+
438467
pub fn break_offset(&mut self, n: usize, off: isize) {
439468
self.scan_break(BreakToken { offset: off, blank_space: n as isize })
440469
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
315315
self.word(cmnt.lines[0].clone());
316316
self.hardbreak()
317317
} else {
318-
self.ibox(0);
318+
self.visual_align();
319319
for line in &cmnt.lines {
320320
if !line.is_empty() {
321321
self.word(line.clone());
@@ -655,7 +655,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
655655
// Outer-box is consistent.
656656
self.cbox(INDENT_UNIT);
657657
// Head-box is inconsistent.
658-
self.ibox(w.len() + 1);
658+
self.ibox(0);
659659
// Keyword that starts the head.
660660
if !w.is_empty() {
661661
self.word_nbsp(w);

compiler/rustc_ast_pretty/src/pprust/state/expr.rs

+16-8
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,9 @@ impl<'a> State<'a> {
320320
self.print_ident(label.ident);
321321
self.word_space(":");
322322
}
323-
self.head("while");
323+
self.cbox(0);
324+
self.ibox(0);
325+
self.word_nbsp("while");
324326
self.print_expr_as_cond(test);
325327
self.space();
326328
self.print_block_with_attrs(blk, attrs);
@@ -330,7 +332,9 @@ impl<'a> State<'a> {
330332
self.print_ident(label.ident);
331333
self.word_space(":");
332334
}
333-
self.head("for");
335+
self.cbox(0);
336+
self.ibox(0);
337+
self.word_nbsp("for");
334338
self.print_pat(pat);
335339
self.space();
336340
self.word_space("in");
@@ -343,12 +347,14 @@ impl<'a> State<'a> {
343347
self.print_ident(label.ident);
344348
self.word_space(":");
345349
}
346-
self.head("loop");
350+
self.cbox(0);
351+
self.ibox(0);
352+
self.word_nbsp("loop");
347353
self.print_block_with_attrs(blk, attrs);
348354
}
349355
ast::ExprKind::Match(ref expr, ref arms) => {
350-
self.cbox(INDENT_UNIT);
351-
self.ibox(INDENT_UNIT);
356+
self.cbox(0);
357+
self.ibox(0);
352358
self.word_nbsp("match");
353359
self.print_expr_as_cond(expr);
354360
self.space();
@@ -388,7 +394,7 @@ impl<'a> State<'a> {
388394
self.word_space(":");
389395
}
390396
// containing cbox, will be closed by print-block at }
391-
self.cbox(INDENT_UNIT);
397+
self.cbox(0);
392398
// head-box, will be closed by print-block after {
393399
self.ibox(0);
394400
self.print_block_with_attrs(blk, attrs);
@@ -397,7 +403,7 @@ impl<'a> State<'a> {
397403
self.word_nbsp("async");
398404
self.print_capture_clause(capture_clause);
399405
// cbox/ibox in analogy to the `ExprKind::Block` arm above
400-
self.cbox(INDENT_UNIT);
406+
self.cbox(0);
401407
self.ibox(0);
402408
self.print_block_with_attrs(blk, attrs);
403409
}
@@ -500,7 +506,9 @@ impl<'a> State<'a> {
500506
self.word("?")
501507
}
502508
ast::ExprKind::TryBlock(ref blk) => {
503-
self.head("try");
509+
self.cbox(0);
510+
self.ibox(0);
511+
self.word_nbsp("try");
504512
self.print_block_with_attrs(blk, attrs)
505513
}
506514
ast::ExprKind::Err => {

compiler/rustc_ast_pretty/src/pprust/state/item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::pp::Breaks::Inconsistent;
2-
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
2+
use crate::pprust::state::{AnnNode, PrintState, State};
33

44
use rustc_ast as ast;
55
use rustc_ast::GenericBound;
@@ -377,7 +377,7 @@ impl<'a> State<'a> {
377377
self.space_if_not_bol();
378378
self.maybe_print_comment(v.span.lo());
379379
self.print_outer_attributes(&v.attrs);
380-
self.ibox(INDENT_UNIT);
380+
self.ibox(0);
381381
self.print_variant(v);
382382
self.word(",");
383383
self.end();

compiler/rustc_infer/src/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ pub struct InferCtxtInner<'tcx> {
195195
// Opaque types found in explicit return types and their
196196
// associated fresh inference variable. Writeback resolves these
197197
// variables to get the concrete type, which can be used to
198-
// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
198+
// 'de-opaque' OpaqueTypeDecl outside of type inference.
199199
pub opaque_types: OpaqueTypeMap<'tcx>,
200200

201201
/// A map from inference variables created from opaque

compiler/rustc_lint/src/context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ impl LintStore {
524524
}
525525
}
526526

527-
/// Context for lint checking after type checking.
527+
/// Context for lint checking outside of type inference.
528528
pub struct LateContext<'tcx> {
529529
/// Type context we're checking in.
530530
pub tcx: TyCtxt<'tcx>,

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -894,7 +894,7 @@ pub struct LocalDecl<'tcx> {
894894
/// across a suspension point against the type components of the generator
895895
/// which type checking knows are live across a suspension point. We need to
896896
/// flag drop flags to avoid triggering this check as they are introduced
897-
/// after typeck.
897+
/// outside of type inference.
898898
///
899899
/// This should be sound because the drop flags are fully algebraic, and
900900
/// therefore don't affect the auto-trait or outlives properties of the

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub struct CommonLifetimes<'tcx> {
220220
/// `ReStatic`
221221
pub re_static: Region<'tcx>,
222222

223-
/// Erased region, used after type-checking
223+
/// Erased region, used outside of type inference.
224224
pub re_erased: Region<'tcx>,
225225
}
226226

@@ -360,7 +360,7 @@ pub struct TypeckResults<'tcx> {
360360
field_indices: ItemLocalMap<usize>,
361361

362362
/// Stores the types for various nodes in the AST. Note that this table
363-
/// is not guaranteed to be populated until after typeck. See
363+
/// is not guaranteed to be populated outside inference. See
364364
/// typeck::check::fn_ctxt for details.
365365
node_types: ItemLocalMap<Ty<'tcx>>,
366366

compiler/rustc_middle/src/ty/normalize_erasing_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ impl<'tcx> TyCtxt<'tcx> {
3434
/// Erase the regions in `value` and then fully normalize all the
3535
/// types found within. The result will also have regions erased.
3636
///
37-
/// This is appropriate to use only after type-check: it assumes
38-
/// that normalization will succeed, for example.
37+
/// This should only be used outside of type inference. For example,
38+
/// it assumes that normalization will succeed.
3939
pub fn normalize_erasing_regions<T>(self, param_env: ty::ParamEnv<'tcx>, value: T) -> T
4040
where
4141
T: TypeFoldable<'tcx>,

compiler/rustc_middle/src/ty/sty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1464,11 +1464,11 @@ pub enum RegionKind {
14641464
/// Static data that has an "infinite" lifetime. Top in the region lattice.
14651465
ReStatic,
14661466

1467-
/// A region variable. Should not exist after typeck.
1467+
/// A region variable. Should not exist outside of type inference.
14681468
ReVar(RegionVid),
14691469

14701470
/// A placeholder region -- basically, the higher-ranked version of `ReFree`.
1471-
/// Should not exist after typeck.
1471+
/// Should not exist outside of type inference.
14721472
RePlaceholder(ty::PlaceholderRegion),
14731473

14741474
/// Empty lifetime is for data that is never accessed. We tag the

compiler/rustc_save_analysis/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -984,7 +984,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
984984
tcx.dep_graph.with_ignore(|| {
985985
info!("Dumping crate {}", cratename);
986986

987-
// Privacy checking requires and is done after type checking; use a
987+
// Privacy checking must be done outside of type inference; use a
988988
// fallback in case the access levels couldn't have been correctly computed.
989989
let access_levels = match tcx.sess.compile_status() {
990990
Ok(..) => tcx.privacy_access_levels(()),

compiler/rustc_target/src/asm/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ impl InlineAsmRegClass {
444444
}
445445

446446
/// Returns a suggested register class to use for this type. This is called
447-
/// after type checking via `supported_types` fails to give a better error
447+
/// when `supported_types` fails to give a better error
448448
/// message to the user.
449449
pub fn suggest_class(self, arch: InlineAsmArch, ty: InlineAsmType) -> Option<Self> {
450450
match self {

compiler/rustc_trait_selection/src/traits/codegen.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc_middle::ty::{self, TyCtxt};
1818
/// that type check should guarantee to us that all nested
1919
/// obligations *could be* resolved if we wanted to.
2020
///
21-
/// Assumes that this is run after the entire crate has been successfully type-checked.
2221
/// This also expects that `trait_ref` is fully normalized.
2322
pub fn codegen_fulfill_obligation<'tcx>(
2423
tcx: TyCtxt<'tcx>,
@@ -101,7 +100,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
101100
/// Finishes processes any obligations that remain in the
102101
/// fulfillment context, and then returns the result with all type
103102
/// variables removed and regions erased. Because this is intended
104-
/// for use after type-check has completed, if any errors occur,
103+
/// for use outside of type inference, if any errors occur,
105104
/// it will panic. It is used during normalization and other cases
106105
/// where processing the obligations in `fulfill_cx` may cause
107106
/// type inference variables that appear in `result` to be
@@ -124,7 +123,10 @@ where
124123
if !errors.is_empty() {
125124
infcx.tcx.sess.delay_span_bug(
126125
rustc_span::DUMMY_SP,
127-
&format!("Encountered errors `{:?}` resolving bounds after type-checking", errors),
126+
&format!(
127+
"Encountered errors `{:?}` resolving bounds outside of type inference",
128+
errors
129+
),
128130
);
129131
}
130132

compiler/rustc_trait_selection/src/traits/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ pub fn normalize_param_env_or_error<'tcx>(
291291
//
292292
// In any case, in practice, typeck constructs all the
293293
// parameter environments once for every fn as it goes,
294-
// and errors will get reported then; so after typeck we
294+
// and errors will get reported then; so outside of type inference we
295295
// can be sure that no errors should occur.
296296

297297
debug!(

compiler/rustc_trait_selection/src/traits/project.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
391391
// severe performance implications for large opaque types with
392392
// late-bound regions. See `issue-88862` benchmark.
393393
ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => {
394-
// Only normalize `impl Trait` after type-checking, usually in codegen.
394+
// Only normalize `impl Trait` outside of type inference, usually in codegen.
395395
match self.param_env.reveal() {
396396
Reveal::UserFacing => ty.super_fold_with(self),
397397

compiler/rustc_trait_selection/src/traits/query/normalize.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ impl<'cx, 'tcx> FallibleTypeFolder<'tcx> for QueryNormalizer<'cx, 'tcx> {
200200
// severe performance implications for large opaque types with
201201
// late-bound regions. See `issue-88862` benchmark.
202202
ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => {
203-
// Only normalize `impl Trait` after type-checking, usually in codegen.
203+
// Only normalize `impl Trait` outside of type inference, usually in codegen.
204204
match self.param_env.reveal() {
205205
Reveal::UserFacing => ty.try_super_fold_with(self),
206206

compiler/rustc_ty_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
149149
// kind of an "idempotent" action, but I'm not sure where would be
150150
// a better place. In practice, we construct environments for
151151
// every fn once during type checking, and we'll abort if there
152-
// are any errors at that point, so after type checking you can be
152+
// are any errors at that point, so outside of type inference you can be
153153
// sure that this will succeed without errors anyway.
154154

155155
if tcx.sess.opts.debugging_opts.chalk {

0 commit comments

Comments
 (0)