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 8 pull requests #93498

Merged
merged 24 commits into from
Jan 31, 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
521b1ee
Improve terminology around "after typeck"
pierwill Oct 25, 2021
d671948
Allow eliding GATs in expr position
compiler-errors Jan 15, 2022
32ab0b8
respect doc(hidden) when suggesting available fields
ibraheemdev Jan 22, 2022
b734abc
Handle unstability as well, including "field typo suggestions"
danielhenrymantilla Jan 24, 2022
ecd06e1
Don't suggest inaccessible fields
terrarier2111 Jan 18, 2022
cd4245d
Make char::DecodeUtf16::size_hist more precise
WaffleLapkin Jan 26, 2022
9c8cd1f
Add a test for `char::DecodeUtf16::size_hint`
WaffleLapkin Jan 26, 2022
2fb617c
Clarify documentation on char::MAX
GKFX Jan 27, 2022
2c97d10
Fix wrong assumption in `DecodeUtf16::size_hint`
WaffleLapkin Jan 28, 2022
f8a013f
Fix some CSS warnings and errors from VS Code
camelid Jan 7, 2022
17cd2cd
Fix an edge case in `chat::DecodeUtf16::size_hint`
WaffleLapkin Jan 30, 2022
9aaf52b
(#93392) Update char::MAX docs and core::char::MAX
GKFX Jan 30, 2022
cb93e9c
Compute indent never relative to current column
dtolnay Jan 21, 2022
8ac05b9
Fix some double indents on exprs containing blocks
dtolnay Jan 21, 2022
402f322
Bless all pretty printer tests and ui tests
dtolnay Jan 21, 2022
125c729
Restore a visual alignment mode for block comments
dtolnay Jan 21, 2022
6749f32
Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726
matthiaskrgr Jan 31, 2022
55d5513
Rollup merge of #92918 - compiler-errors:gat-expr-lifetime-elision, r…
matthiaskrgr Jan 31, 2022
71efe90
Rollup merge of #93039 - terrarier2111:fix-field-help, r=nagisa
matthiaskrgr Jan 31, 2022
1cb22e4
Rollup merge of #93155 - dtolnay:blockindent, r=nagisa
matthiaskrgr Jan 31, 2022
7de90d5
Rollup merge of #93214 - ibraheemdev:issue-93210, r=davidtwco
matthiaskrgr Jan 31, 2022
76857fb
Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_h…
matthiaskrgr Jan 31, 2022
c03bf54
Rollup merge of #93392 - GKFX:char-docs, r=scottmcm
matthiaskrgr Jan 31, 2022
2070b22
Rollup merge of #93444 - camelid:rustdoc-css-cleanup, r=GuillaumeGome…
matthiaskrgr Jan 31, 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
69 changes: 49 additions & 20 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ pub enum Breaks {
Inconsistent,
}

#[derive(Clone, Copy)]
enum IndentStyle {
/// Vertically aligned under whatever column this block begins at.
///
/// fn demo(arg1: usize,
/// arg2: usize);
Visual,
/// Indented relative to the indentation level of the previous line.
///
/// fn demo(
/// arg1: usize,
/// arg2: usize,
/// );
Block { offset: isize },
}

#[derive(Clone, Copy)]
pub struct BreakToken {
offset: isize,
Expand All @@ -154,7 +170,7 @@ pub struct BreakToken {

#[derive(Clone, Copy)]
pub struct BeginToken {
offset: isize,
indent: IndentStyle,
breaks: Breaks,
}

Expand All @@ -178,7 +194,7 @@ impl Token {
#[derive(Copy, Clone)]
enum PrintFrame {
Fits,
Broken { offset: isize, breaks: Breaks },
Broken { indent: usize, breaks: Breaks },
}

const SIZE_INFINITY: isize = 0xffff;
Expand All @@ -204,6 +220,8 @@ pub struct Printer {
scan_stack: VecDeque<usize>,
/// Stack of blocks-in-progress being flushed by print
print_stack: Vec<PrintFrame>,
/// Level of indentation of current line
indent: usize,
/// Buffered indentation to avoid writing trailing whitespace
pending_indentation: isize,
/// The token most recently popped from the left boundary of the
Expand All @@ -229,6 +247,7 @@ impl Printer {
right_total: 0,
scan_stack: VecDeque::new(),
print_stack: Vec::new(),
indent: 0,
pending_indentation: 0,
last_printed: None,
}
Expand Down Expand Up @@ -368,38 +387,41 @@ impl Printer {
*self
.print_stack
.last()
.unwrap_or(&PrintFrame::Broken { offset: 0, breaks: Breaks::Inconsistent })
.unwrap_or(&PrintFrame::Broken { indent: 0, breaks: Breaks::Inconsistent })
}

fn print_begin(&mut self, token: BeginToken, size: isize) {
if size > self.space {
let col = self.margin - self.space + token.offset;
self.print_stack.push(PrintFrame::Broken { offset: col, breaks: token.breaks });
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
self.indent = match token.indent {
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
IndentStyle::Visual => (self.margin - self.space) as usize,
};
} else {
self.print_stack.push(PrintFrame::Fits);
}
}

fn print_end(&mut self) {
self.print_stack.pop().unwrap();
if let PrintFrame::Broken { indent, .. } = self.print_stack.pop().unwrap() {
self.indent = indent;
}
}

fn print_break(&mut self, token: BreakToken, size: isize) {
let break_offset =
match self.get_top() {
PrintFrame::Fits => None,
PrintFrame::Broken { offset, breaks: Breaks::Consistent } => Some(offset),
PrintFrame::Broken { offset, breaks: Breaks::Inconsistent } => {
if size > self.space { Some(offset) } else { None }
}
};
if let Some(offset) = break_offset {
self.out.push('\n');
self.pending_indentation = offset + token.offset;
self.space = self.margin - (offset + token.offset);
} else {
let fits = match self.get_top() {
PrintFrame::Fits => true,
PrintFrame::Broken { breaks: Breaks::Consistent, .. } => false,
PrintFrame::Broken { breaks: Breaks::Inconsistent, .. } => size <= self.space,
};
if fits {
self.pending_indentation += token.blank_space;
self.space -= token.blank_space;
} else {
self.out.push('\n');
let indent = self.indent as isize + token.offset;
self.pending_indentation = indent;
self.space = self.margin - indent;
}
}

Expand All @@ -422,7 +444,10 @@ impl Printer {

/// "raw box"
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
self.scan_begin(BeginToken { offset: indent as isize, breaks })
self.scan_begin(BeginToken {
indent: IndentStyle::Block { offset: indent as isize },
breaks,
})
}

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

pub fn visual_align(&mut self) {
self.scan_begin(BeginToken { indent: IndentStyle::Visual, breaks: Breaks::Consistent });
}

pub fn break_offset(&mut self, n: usize, off: isize) {
self.scan_break(BreakToken { offset: off, blank_space: n as isize })
}
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 @@ -315,7 +315,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.word(cmnt.lines[0].clone());
self.hardbreak()
} else {
self.ibox(0);
self.visual_align();
for line in &cmnt.lines {
if !line.is_empty() {
self.word(line.clone());
Expand Down Expand Up @@ -655,7 +655,7 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
// Outer-box is consistent.
self.cbox(INDENT_UNIT);
// Head-box is inconsistent.
self.ibox(w.len() + 1);
self.ibox(0);
// Keyword that starts the head.
if !w.is_empty() {
self.word_nbsp(w);
Expand Down
24 changes: 16 additions & 8 deletions compiler/rustc_ast_pretty/src/pprust/state/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,9 @@ impl<'a> State<'a> {
self.print_ident(label.ident);
self.word_space(":");
}
self.head("while");
self.cbox(0);
self.ibox(0);
self.word_nbsp("while");
self.print_expr_as_cond(test);
self.space();
self.print_block_with_attrs(blk, attrs);
Expand All @@ -330,7 +332,9 @@ impl<'a> State<'a> {
self.print_ident(label.ident);
self.word_space(":");
}
self.head("for");
self.cbox(0);
self.ibox(0);
self.word_nbsp("for");
self.print_pat(pat);
self.space();
self.word_space("in");
Expand All @@ -343,12 +347,14 @@ impl<'a> State<'a> {
self.print_ident(label.ident);
self.word_space(":");
}
self.head("loop");
self.cbox(0);
self.ibox(0);
self.word_nbsp("loop");
self.print_block_with_attrs(blk, attrs);
}
ast::ExprKind::Match(ref expr, ref arms) => {
self.cbox(INDENT_UNIT);
self.ibox(INDENT_UNIT);
self.cbox(0);
self.ibox(0);
self.word_nbsp("match");
self.print_expr_as_cond(expr);
self.space();
Expand Down Expand Up @@ -388,7 +394,7 @@ impl<'a> State<'a> {
self.word_space(":");
}
// containing cbox, will be closed by print-block at }
self.cbox(INDENT_UNIT);
self.cbox(0);
// head-box, will be closed by print-block after {
self.ibox(0);
self.print_block_with_attrs(blk, attrs);
Expand All @@ -397,7 +403,7 @@ impl<'a> State<'a> {
self.word_nbsp("async");
self.print_capture_clause(capture_clause);
// cbox/ibox in analogy to the `ExprKind::Block` arm above
self.cbox(INDENT_UNIT);
self.cbox(0);
self.ibox(0);
self.print_block_with_attrs(blk, attrs);
}
Expand Down Expand Up @@ -500,7 +506,9 @@ impl<'a> State<'a> {
self.word("?")
}
ast::ExprKind::TryBlock(ref blk) => {
self.head("try");
self.cbox(0);
self.ibox(0);
self.word_nbsp("try");
self.print_block_with_attrs(blk, attrs)
}
ast::ExprKind::Err => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::pp::Breaks::Inconsistent;
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
use crate::pprust::state::{AnnNode, PrintState, State};

use rustc_ast as ast;
use rustc_ast::GenericBound;
Expand Down Expand Up @@ -377,7 +377,7 @@ impl<'a> State<'a> {
self.space_if_not_bol();
self.maybe_print_comment(v.span.lo());
self.print_outer_attributes(&v.attrs);
self.ibox(INDENT_UNIT);
self.ibox(0);
self.print_variant(v);
self.word(",");
self.end();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ pub struct InferCtxtInner<'tcx> {
// Opaque types found in explicit return types and their
// associated fresh inference variable. Writeback resolves these
// variables to get the concrete type, which can be used to
// 'de-opaque' OpaqueTypeDecl, after typeck is done with all functions.
// 'de-opaque' OpaqueTypeDecl outside of type inference.
pub opaque_types: OpaqueTypeMap<'tcx>,

/// A map from inference variables created from opaque
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ impl LintStore {
}
}

/// Context for lint checking after type checking.
/// Context for lint checking outside of type inference.
pub struct LateContext<'tcx> {
/// Type context we're checking in.
pub tcx: TyCtxt<'tcx>,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ pub struct LocalDecl<'tcx> {
/// across a suspension point against the type components of the generator
/// which type checking knows are live across a suspension point. We need to
/// flag drop flags to avoid triggering this check as they are introduced
/// after typeck.
/// outside of type inference.
///
/// This should be sound because the drop flags are fully algebraic, and
/// therefore don't affect the auto-trait or outlives properties of the
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ pub struct CommonLifetimes<'tcx> {
/// `ReStatic`
pub re_static: Region<'tcx>,

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

Expand Down Expand Up @@ -360,7 +360,7 @@ pub struct TypeckResults<'tcx> {
field_indices: ItemLocalMap<usize>,

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

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/normalize_erasing_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ impl<'tcx> TyCtxt<'tcx> {
/// Erase the regions in `value` and then fully normalize all the
/// types found within. The result will also have regions erased.
///
/// This is appropriate to use only after type-check: it assumes
/// that normalization will succeed, for example.
/// This should only be used outside of type inference. For example,
/// it assumes that normalization will succeed.
pub fn normalize_erasing_regions<T>(self, param_env: ty::ParamEnv<'tcx>, value: T) -> T
where
T: TypeFoldable<'tcx>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1464,11 +1464,11 @@ pub enum RegionKind {
/// Static data that has an "infinite" lifetime. Top in the region lattice.
ReStatic,

/// A region variable. Should not exist after typeck.
/// A region variable. Should not exist outside of type inference.
ReVar(RegionVid),

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

/// Empty lifetime is for data that is never accessed. We tag the
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_save_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -984,7 +984,7 @@ pub fn process_crate<'l, 'tcx, H: SaveHandler>(
tcx.dep_graph.with_ignore(|| {
info!("Dumping crate {}", cratename);

// Privacy checking requires and is done after type checking; use a
// Privacy checking must be done outside of type inference; use a
// fallback in case the access levels couldn't have been correctly computed.
let access_levels = match tcx.sess.compile_status() {
Ok(..) => tcx.privacy_access_levels(()),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_target/src/asm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ impl InlineAsmRegClass {
}

/// Returns a suggested register class to use for this type. This is called
/// after type checking via `supported_types` fails to give a better error
/// when `supported_types` fails to give a better error
/// message to the user.
pub fn suggest_class(self, arch: InlineAsmArch, ty: InlineAsmType) -> Option<Self> {
match self {
Expand Down
8 changes: 5 additions & 3 deletions compiler/rustc_trait_selection/src/traits/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use rustc_middle::ty::{self, TyCtxt};
/// that type check should guarantee to us that all nested
/// obligations *could be* resolved if we wanted to.
///
/// Assumes that this is run after the entire crate has been successfully type-checked.
/// This also expects that `trait_ref` is fully normalized.
pub fn codegen_fulfill_obligation<'tcx>(
tcx: TyCtxt<'tcx>,
Expand Down Expand Up @@ -101,7 +100,7 @@ pub fn codegen_fulfill_obligation<'tcx>(
/// Finishes processes any obligations that remain in the
/// fulfillment context, and then returns the result with all type
/// variables removed and regions erased. Because this is intended
/// for use after type-check has completed, if any errors occur,
/// for use outside of type inference, if any errors occur,
/// it will panic. It is used during normalization and other cases
/// where processing the obligations in `fulfill_cx` may cause
/// type inference variables that appear in `result` to be
Expand All @@ -124,7 +123,10 @@ where
if !errors.is_empty() {
infcx.tcx.sess.delay_span_bug(
rustc_span::DUMMY_SP,
&format!("Encountered errors `{:?}` resolving bounds after type-checking", errors),
&format!(
"Encountered errors `{:?}` resolving bounds outside of type inference",
errors
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn normalize_param_env_or_error<'tcx>(
//
// In any case, in practice, typeck constructs all the
// parameter environments once for every fn as it goes,
// and errors will get reported then; so after typeck we
// and errors will get reported then; so outside of type inference we
// can be sure that no errors should occur.

debug!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ impl<'a, 'b, 'tcx> TypeFolder<'tcx> for AssocTypeNormalizer<'a, 'b, 'tcx> {
// severe performance implications for large opaque types with
// late-bound regions. See `issue-88862` benchmark.
ty::Opaque(def_id, substs) if !substs.has_escaping_bound_vars() => {
// Only normalize `impl Trait` after type-checking, usually in codegen.
// Only normalize `impl Trait` outside of type inference, usually in codegen.
match self.param_env.reveal() {
Reveal::UserFacing => ty.super_fold_with(self),

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

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> {
// kind of an "idempotent" action, but I'm not sure where would be
// a better place. In practice, we construct environments for
// every fn once during type checking, and we'll abort if there
// are any errors at that point, so after type checking you can be
// are any errors at that point, so outside of type inference you can be
// sure that this will succeed without errors anyway.

if tcx.sess.opts.debugging_opts.chalk {
Expand Down
Loading