Skip to content

Commit

Permalink
Auto merge of rust-lang#91555 - matthiaskrgr:rollup-pq0iaq7, r=matthi…
Browse files Browse the repository at this point in the history
…askrgr

Rollup of 4 pull requests

Successful merges:

 - rust-lang#90529 (Skip reborrows in AbstractConstBuilder)
 - rust-lang#91437 (Pretty print empty blocks as {})
 - rust-lang#91450 (Don't suggest types whose inner type is erroneous)
 - rust-lang#91535 (Stabilize `-Z emit-future-incompat` as `--json future-incompat`)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Dec 5, 2021
2 parents 1597728 + 068b304 commit 772d51f
Show file tree
Hide file tree
Showing 76 changed files with 271 additions and 180 deletions.
68 changes: 44 additions & 24 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.strsep(",", false, b, elts, op)
}

fn maybe_print_comment(&mut self, pos: BytePos) {
fn maybe_print_comment(&mut self, pos: BytePos) -> bool {
let mut has_comment = false;
while let Some(ref cmnt) = self.next_comment() {
if cmnt.pos < pos {
has_comment = true;
self.print_comment(cmnt);
} else {
break;
}
}
has_comment
}

fn print_comment(&mut self, cmnt: &Comment) {
Expand Down Expand Up @@ -570,7 +573,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.print_tts(tts, convert_dollar_crate);
self.end();
match delim {
DelimToken::Brace => self.bclose(span),
DelimToken::Brace => {
let empty = tts.is_empty();
self.bclose(span, empty);
}
_ => {
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
self.word(token_str)
Expand Down Expand Up @@ -642,17 +648,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
self.end(); // Close the head-box.
}

fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
self.maybe_print_comment(span.hi());
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
let has_comment = self.maybe_print_comment(span.hi());
if !empty || has_comment {
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
}
self.word("}");
if close_box {
self.end(); // Close the outer-box.
}
}

fn bclose(&mut self, span: rustc_span::Span) {
self.bclose_maybe_open(span, true)
fn bclose(&mut self, span: rustc_span::Span, empty: bool) {
let close_box = true;
self.bclose_maybe_open(span, empty, close_box)
}

fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
Expand Down Expand Up @@ -1196,7 +1205,8 @@ impl<'a> State<'a> {
for item in items {
self.print_item(item);
}
self.bclose(item.span);
let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
}
ModKind::Unloaded => {
self.s.word(";");
Expand All @@ -1216,7 +1226,8 @@ impl<'a> State<'a> {
}
self.bopen();
self.print_foreign_mod(nmod, &item.attrs);
self.bclose(item.span);
let empty = item.attrs.is_empty() && nmod.items.is_empty();
self.bclose(item.span, empty);
}
ast::ItemKind::GlobalAsm(ref asm) => {
self.head(visibility_qualified(&item.vis, "global_asm!"));
Expand Down Expand Up @@ -1291,7 +1302,8 @@ impl<'a> State<'a> {
for impl_item in items {
self.print_assoc_item(impl_item);
}
self.bclose(item.span);
let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
}
ast::ItemKind::Trait(box ast::Trait {
is_auto,
Expand Down Expand Up @@ -1326,7 +1338,8 @@ impl<'a> State<'a> {
for trait_item in items {
self.print_assoc_item(trait_item);
}
self.bclose(item.span);
let empty = item.attrs.is_empty() && items.is_empty();
self.bclose(item.span, empty);
}
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
self.head("");
Expand Down Expand Up @@ -1410,7 +1423,8 @@ impl<'a> State<'a> {
self.end();
self.maybe_print_trailing_comment(v.span, None);
}
self.bclose(span)
let empty = variants.is_empty();
self.bclose(span, empty)
}

crate fn print_visibility(&mut self, vis: &ast::Visibility) {
Expand Down Expand Up @@ -1441,20 +1455,24 @@ impl<'a> State<'a> {
crate fn print_record_struct_body(&mut self, fields: &[ast::FieldDef], span: rustc_span::Span) {
self.nbsp();
self.bopen();
self.hardbreak_if_not_bol();

for field in fields {
let empty = fields.is_empty();
if !empty {
self.hardbreak_if_not_bol();
self.maybe_print_comment(field.span.lo());
self.print_outer_attributes(&field.attrs);
self.print_visibility(&field.vis);
self.print_ident(field.ident.unwrap());
self.word_nbsp(":");
self.print_type(&field.ty);
self.s.word(",");

for field in fields {
self.hardbreak_if_not_bol();
self.maybe_print_comment(field.span.lo());
self.print_outer_attributes(&field.attrs);
self.print_visibility(&field.vis);
self.print_ident(field.ident.unwrap());
self.word_nbsp(":");
self.print_type(&field.ty);
self.s.word(",");
}
}

self.bclose(span)
self.bclose(span, empty);
}

crate fn print_struct(
Expand Down Expand Up @@ -1633,7 +1651,8 @@ impl<'a> State<'a> {
}
}

self.bclose_maybe_open(blk.span, close_box);
let empty = attrs.is_empty() && blk.stmts.is_empty();
self.bclose_maybe_open(blk.span, empty, close_box);
self.ann.post(self, AnnNode::Block(blk))
}

Expand Down Expand Up @@ -2010,7 +2029,8 @@ impl<'a> State<'a> {
for arm in arms {
self.print_arm(arm);
}
self.bclose(expr.span);
let empty = attrs.is_empty() && arms.is_empty();
self.bclose(expr.span, empty);
}
ast::ExprKind::Closure(
capture_clause,
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 @@ -2174,7 +2174,7 @@ impl<'a> State<'a> {
match decl.output {
hir::FnRetTy::Return(ref ty) => {
self.print_type(&ty);
self.maybe_print_comment(ty.span.lo())
self.maybe_print_comment(ty.span.lo());
}
hir::FnRetTy::DefaultReturn(..) => unreachable!(),
}
Expand Down Expand Up @@ -2368,7 +2368,7 @@ impl<'a> State<'a> {
self.end();

if let hir::FnRetTy::Return(ref output) = decl.output {
self.maybe_print_comment(output.span.lo())
self.maybe_print_comment(output.span.lo());
}
}

Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,6 @@ fn test_debugging_options_tracking_hash() {
untracked!(dump_mir_dir, String::from("abc"));
untracked!(dump_mir_exclude_pass_number, true);
untracked!(dump_mir_graphviz, true);
untracked!(emit_future_incompat_report, true);
untracked!(emit_stack_sizes, true);
untracked!(future_incompat_test, true);
untracked!(hir_stats, true);
Expand Down
14 changes: 12 additions & 2 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ impl Default for Options {
edition: DEFAULT_EDITION,
json_artifact_notifications: false,
json_unused_externs: false,
json_future_incompat: false,
pretty: None,
working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()),
}
Expand Down Expand Up @@ -1257,6 +1258,7 @@ pub struct JsonConfig {
pub json_rendered: HumanReadableErrorType,
pub json_artifact_notifications: bool,
pub json_unused_externs: bool,
pub json_future_incompat: bool,
}

/// Parse the `--json` flag.
Expand All @@ -1269,6 +1271,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
let mut json_color = ColorConfig::Never;
let mut json_artifact_notifications = false;
let mut json_unused_externs = false;
let mut json_future_incompat = false;
for option in matches.opt_strs("json") {
// For now conservatively forbid `--color` with `--json` since `--json`
// won't actually be emitting any colors and anything colorized is
Expand All @@ -1286,6 +1289,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
"artifacts" => json_artifact_notifications = true,
"unused-externs" => json_unused_externs = true,
"future-incompat" => json_future_incompat = true,
s => early_error(
ErrorOutputType::default(),
&format!("unknown `--json` option `{}`", s),
Expand All @@ -1298,6 +1302,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
json_rendered: json_rendered(json_color),
json_artifact_notifications,
json_unused_externs,
json_future_incompat,
}
}

Expand Down Expand Up @@ -2011,8 +2016,12 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {

let edition = parse_crate_edition(matches);

let JsonConfig { json_rendered, json_artifact_notifications, json_unused_externs } =
parse_json(matches);
let JsonConfig {
json_rendered,
json_artifact_notifications,
json_unused_externs,
json_future_incompat,
} = parse_json(matches);

let error_format = parse_error_format(matches, color, json_rendered);

Expand Down Expand Up @@ -2248,6 +2257,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
edition,
json_artifact_notifications,
json_unused_externs,
json_future_incompat,
pretty,
working_dir,
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,9 @@ top_level_options!(
/// `true` if we're emitting a JSON blob containing the unused externs
json_unused_externs: bool [UNTRACKED],

/// `true` if we're emitting a JSON job containg a future-incompat report for lints
json_future_incompat: bool [TRACKED],

pretty: Option<PpMode> [UNTRACKED],

/// The (potentially remapped) working directory
Expand Down Expand Up @@ -1147,8 +1150,6 @@ options! {
computed `block` spans (one span encompassing a block's terminator and \
all statements). If `-Z instrument-coverage` is also enabled, create \
an additional `.html` file showing the computed coverage spans."),
emit_future_incompat_report: bool = (false, parse_bool, [UNTRACKED],
"emits a future-incompatibility report for lints (RFC 2834)"),
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
"emit a section containing stack size metadata (default: no)"),
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ impl Session {
}

fn emit_future_breakage(&self) {
if !self.opts.debugging_opts.emit_future_incompat_report {
if !self.opts.json_future_incompat {
return;
}

Expand Down
22 changes: 17 additions & 5 deletions compiler/rustc_trait_selection/src/traits/const_evaluatable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,13 +399,25 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
let arg = self.recurse_build(source)?;
self.nodes.push(Node::Cast(abstract_const::CastKind::As, arg, node.ty))
}

ExprKind::Borrow{ arg, ..} => {
let arg_node = &self.body.exprs[*arg];

// Skip reborrows for now until we allow Deref/Borrow/AddressOf
// expressions.
// FIXME(generic_const_exprs): Verify/explain why this is sound
if let ExprKind::Deref {arg} = arg_node.kind {
self.recurse_build(arg)?
} else {
self.maybe_supported_error(
node.span,
"borrowing is not supported in generic constants",
)?
}
}
// FIXME(generic_const_exprs): We may want to support these.
ExprKind::AddressOf { .. }
| ExprKind::Borrow { .. }
| ExprKind::Deref { .. } => self.maybe_supported_error(
ExprKind::AddressOf { .. } | ExprKind::Deref {..}=> self.maybe_supported_error(
node.span,
"dereferencing is not supported in generic constants",
"dereferencing or taking the address is not supported in generic constants",
)?,
ExprKind::Repeat { .. } | ExprKind::Array { .. } => self.maybe_supported_error(
node.span,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use rustc_middle::ty::subst::InternalSubsts;
use rustc_middle::ty::util::Discr;
use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, Ty, TyCtxt};
use rustc_middle::ty::{ReprOptions, ToPredicate, WithConstness};
use rustc_middle::ty::{ReprOptions, ToPredicate, TypeFoldable, WithConstness};
use rustc_session::lint;
use rustc_session::parse::feature_err;
use rustc_span::symbol::{kw, sym, Ident, Symbol};
Expand Down Expand Up @@ -1777,7 +1777,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
visitor.visit_ty(ty);
let mut diag = bad_placeholder_type(tcx, visitor.0, "return type");
let ret_ty = fn_sig.skip_binder().output();
if ret_ty != tcx.ty_error() {
if !ret_ty.references_error() {
if !ret_ty.is_closure() {
let ret_ty_str = match ret_ty.kind() {
// Suggest a function pointer return type instead of a unique function definition
Expand Down
8 changes: 4 additions & 4 deletions src/test/pretty/ast-stmt-expr-attr.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// pp-exact

fn main() { }
fn main() {}

#[cfg(FALSE)]
fn syntax() {
Expand Down Expand Up @@ -117,7 +117,7 @@ fn syntax() {
let _ = #[attr] foo!(#! [attr]);
let _ = #[attr] foo![];
let _ = #[attr] foo![#! [attr]];
let _ = #[attr] foo! { };
let _ = #[attr] foo! {};
let _ = #[attr] foo! { #! [attr] };
let _ = #[attr] Foo{bar: baz,};
let _ = #[attr] Foo{..foo};
Expand All @@ -135,7 +135,7 @@ fn syntax() {
foo!();

#[attr]
foo! { }
foo! {}

#[attr]
foo![];
Expand Down Expand Up @@ -170,6 +170,6 @@ fn syntax() {
{

#[attr]
foo! { }
foo! {}
}
}
2 changes: 1 addition & 1 deletion src/test/pretty/attr-derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ enum Enum {
Qwerty,
}

fn main() { }
fn main() {}
6 changes: 3 additions & 3 deletions src/test/pretty/auto-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// pp-exact

auto trait MyTrait { }
auto trait MyTrait {}

unsafe auto trait UnsafeMyTrait { }
unsafe auto trait UnsafeMyTrait {}

pub fn main() { }
pub fn main() {}
9 changes: 4 additions & 5 deletions src/test/pretty/block-comment-trailing-whitespace2.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// compile-flags: --crate-type=lib

// pp-exact
fn f() {
} /*
The next line should not be indented.
fn f() {} /*
The next line should not be indented.
That one. It shouldn't have been indented.
*/
That one. It shouldn't have been indented.
*/
Loading

0 comments on commit 772d51f

Please sign in to comment.