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 #93491

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
3f609b7
Make `span_extend_to_prev_str()` more robust
FabianWolff Jan 15, 2022
104961e
Compute indent never relative to current column
dtolnay Jan 21, 2022
956f1ca
Fix some double indents on exprs containing blocks
dtolnay Jan 21, 2022
03e4001
Bless all pretty printer tests and ui tests
dtolnay Jan 21, 2022
269b5a4
Restore a visual alignment mode for block comments
dtolnay Jan 21, 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
2c97d10
Fix wrong assumption in `DecodeUtf16::size_hint`
WaffleLapkin Jan 28, 2022
0189a21
Document `SystemTime` platform precision
ChrisDenton Jan 29, 2022
d70b9c0
unix: Use metadata for `DirEntry::file_type` fallback
cuviper Jan 30, 2022
17cd2cd
Fix an edge case in `chat::DecodeUtf16::size_hint`
WaffleLapkin Jan 30, 2022
cde240c
core: Remove some redundant {}s from the sorting code
est31 Jan 30, 2022
78efb07
review the total_cmp documentation
nagisa Jan 28, 2022
99fd534
Rollup merge of #90277 - pierwill:fix-70258-inference-terms, r=jackh726
matthiaskrgr Jan 30, 2022
1b22492
Rollup merge of #91607 - FabianWolff:issue-91560-const-span, r=jackh726
matthiaskrgr Jan 30, 2022
ef64c52
Rollup merge of #92918 - compiler-errors:gat-expr-lifetime-elision, r…
matthiaskrgr Jan 30, 2022
781ed1e
Rollup merge of #93039 - terrarier2111:fix-field-help, r=nagisa
matthiaskrgr Jan 30, 2022
b3f609b
Rollup merge of #93155 - dtolnay:blockindent, r=nagisa
matthiaskrgr Jan 30, 2022
b984ac0
Rollup merge of #93347 - WaffleLapkin:better_char_decode_utf16_size_h…
matthiaskrgr Jan 30, 2022
02b5ff3
Rollup merge of #93403 - nagisa:total-cmp-review, r=joshtriplett
matthiaskrgr Jan 30, 2022
ed50b23
Rollup merge of #93462 - ChrisDenton:systime-doc, r=joshtriplett
matthiaskrgr Jan 30, 2022
6007644
Rollup merge of #93471 - cuviper:direntry-file_type-stat, r=the8472
matthiaskrgr Jan 30, 2022
060bfcf
Rollup merge of #93485 - est31:remove_curly, r=joshtriplett
matthiaskrgr Jan 30, 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
38 changes: 19 additions & 19 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -453,28 +453,28 @@ impl<'a> Resolver<'a> {
// edit:
// only do this if the const and usage of the non-constant value are on the same line
// the further the two are apart, the higher the chance of the suggestion being wrong
// also make sure that the pos for the suggestion is not 0 (ICE #90878)

let sp =
self.session.source_map().span_extend_to_prev_str(ident.span, current, true);

let pos_for_suggestion = sp.lo().0.saturating_sub(current.len() as u32);
let sp = self
.session
.source_map()
.span_extend_to_prev_str(ident.span, current, true, false);

if sp.lo().0 == 0
|| pos_for_suggestion == 0
|| self.session.source_map().is_multiline(sp)
{
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
} else {
let sp = sp.with_lo(BytePos(pos_for_suggestion));
err.span_suggestion(
sp,
&format!("consider using `{}` instead of `{}`", sugg, current),
format!("{} {}", sugg, ident),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
match sp {
Some(sp) if !self.session.source_map().is_multiline(sp) => {
let sp = sp.with_lo(BytePos(sp.lo().0 - (current.len() as u32)));
err.span_suggestion(
sp,
&format!("consider using `{}` instead of `{}`", sugg, current),
format!("{} {}", sugg, ident),
Applicability::MaybeIncorrect,
);
err.span_label(span, "non-constant value");
}
_ => {
err.span_label(ident.span, &format!("this would need to be a `{}`", sugg));
}
}

err
}
ResolutionError::BindingShadowsSomethingUnacceptable {
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
Loading