Skip to content

Commit 772d51f

Browse files
committed
Auto merge of #91555 - matthiaskrgr:rollup-pq0iaq7, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #90529 (Skip reborrows in AbstractConstBuilder) - #91437 (Pretty print empty blocks as {}) - #91450 (Don't suggest types whose inner type is erroneous) - #91535 (Stabilize `-Z emit-future-incompat` as `--json future-incompat`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 1597728 + 068b304 commit 772d51f

File tree

76 files changed

+271
-180
lines changed

Some content is hidden

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

76 files changed

+271
-180
lines changed

Diff for: compiler/rustc_ast_pretty/src/pprust/state.rs

+44-24
Original file line numberDiff line numberDiff line change
@@ -263,14 +263,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
263263
self.strsep(",", false, b, elts, op)
264264
}
265265

266-
fn maybe_print_comment(&mut self, pos: BytePos) {
266+
fn maybe_print_comment(&mut self, pos: BytePos) -> bool {
267+
let mut has_comment = false;
267268
while let Some(ref cmnt) = self.next_comment() {
268269
if cmnt.pos < pos {
270+
has_comment = true;
269271
self.print_comment(cmnt);
270272
} else {
271273
break;
272274
}
273275
}
276+
has_comment
274277
}
275278

276279
fn print_comment(&mut self, cmnt: &Comment) {
@@ -570,7 +573,10 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
570573
self.print_tts(tts, convert_dollar_crate);
571574
self.end();
572575
match delim {
573-
DelimToken::Brace => self.bclose(span),
576+
DelimToken::Brace => {
577+
let empty = tts.is_empty();
578+
self.bclose(span, empty);
579+
}
574580
_ => {
575581
let token_str = self.token_kind_to_string(&token::CloseDelim(delim));
576582
self.word(token_str)
@@ -642,17 +648,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
642648
self.end(); // Close the head-box.
643649
}
644650

645-
fn bclose_maybe_open(&mut self, span: rustc_span::Span, close_box: bool) {
646-
self.maybe_print_comment(span.hi());
647-
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
651+
fn bclose_maybe_open(&mut self, span: rustc_span::Span, empty: bool, close_box: bool) {
652+
let has_comment = self.maybe_print_comment(span.hi());
653+
if !empty || has_comment {
654+
self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize));
655+
}
648656
self.word("}");
649657
if close_box {
650658
self.end(); // Close the outer-box.
651659
}
652660
}
653661

654-
fn bclose(&mut self, span: rustc_span::Span) {
655-
self.bclose_maybe_open(span, true)
662+
fn bclose(&mut self, span: rustc_span::Span, empty: bool) {
663+
let close_box = true;
664+
self.bclose_maybe_open(span, empty, close_box)
656665
}
657666

658667
fn break_offset_if_not_bol(&mut self, n: usize, off: isize) {
@@ -1196,7 +1205,8 @@ impl<'a> State<'a> {
11961205
for item in items {
11971206
self.print_item(item);
11981207
}
1199-
self.bclose(item.span);
1208+
let empty = item.attrs.is_empty() && items.is_empty();
1209+
self.bclose(item.span, empty);
12001210
}
12011211
ModKind::Unloaded => {
12021212
self.s.word(";");
@@ -1216,7 +1226,8 @@ impl<'a> State<'a> {
12161226
}
12171227
self.bopen();
12181228
self.print_foreign_mod(nmod, &item.attrs);
1219-
self.bclose(item.span);
1229+
let empty = item.attrs.is_empty() && nmod.items.is_empty();
1230+
self.bclose(item.span, empty);
12201231
}
12211232
ast::ItemKind::GlobalAsm(ref asm) => {
12221233
self.head(visibility_qualified(&item.vis, "global_asm!"));
@@ -1291,7 +1302,8 @@ impl<'a> State<'a> {
12911302
for impl_item in items {
12921303
self.print_assoc_item(impl_item);
12931304
}
1294-
self.bclose(item.span);
1305+
let empty = item.attrs.is_empty() && items.is_empty();
1306+
self.bclose(item.span, empty);
12951307
}
12961308
ast::ItemKind::Trait(box ast::Trait {
12971309
is_auto,
@@ -1326,7 +1338,8 @@ impl<'a> State<'a> {
13261338
for trait_item in items {
13271339
self.print_assoc_item(trait_item);
13281340
}
1329-
self.bclose(item.span);
1341+
let empty = item.attrs.is_empty() && items.is_empty();
1342+
self.bclose(item.span, empty);
13301343
}
13311344
ast::ItemKind::TraitAlias(ref generics, ref bounds) => {
13321345
self.head("");
@@ -1410,7 +1423,8 @@ impl<'a> State<'a> {
14101423
self.end();
14111424
self.maybe_print_trailing_comment(v.span, None);
14121425
}
1413-
self.bclose(span)
1426+
let empty = variants.is_empty();
1427+
self.bclose(span, empty)
14141428
}
14151429

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

1446-
for field in fields {
1459+
let empty = fields.is_empty();
1460+
if !empty {
14471461
self.hardbreak_if_not_bol();
1448-
self.maybe_print_comment(field.span.lo());
1449-
self.print_outer_attributes(&field.attrs);
1450-
self.print_visibility(&field.vis);
1451-
self.print_ident(field.ident.unwrap());
1452-
self.word_nbsp(":");
1453-
self.print_type(&field.ty);
1454-
self.s.word(",");
1462+
1463+
for field in fields {
1464+
self.hardbreak_if_not_bol();
1465+
self.maybe_print_comment(field.span.lo());
1466+
self.print_outer_attributes(&field.attrs);
1467+
self.print_visibility(&field.vis);
1468+
self.print_ident(field.ident.unwrap());
1469+
self.word_nbsp(":");
1470+
self.print_type(&field.ty);
1471+
self.s.word(",");
1472+
}
14551473
}
14561474

1457-
self.bclose(span)
1475+
self.bclose(span, empty);
14581476
}
14591477

14601478
crate fn print_struct(
@@ -1633,7 +1651,8 @@ impl<'a> State<'a> {
16331651
}
16341652
}
16351653

1636-
self.bclose_maybe_open(blk.span, close_box);
1654+
let empty = attrs.is_empty() && blk.stmts.is_empty();
1655+
self.bclose_maybe_open(blk.span, empty, close_box);
16371656
self.ann.post(self, AnnNode::Block(blk))
16381657
}
16391658

@@ -2010,7 +2029,8 @@ impl<'a> State<'a> {
20102029
for arm in arms {
20112030
self.print_arm(arm);
20122031
}
2013-
self.bclose(expr.span);
2032+
let empty = attrs.is_empty() && arms.is_empty();
2033+
self.bclose(expr.span, empty);
20142034
}
20152035
ast::ExprKind::Closure(
20162036
capture_clause,

Diff for: compiler/rustc_hir_pretty/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2174,7 +2174,7 @@ impl<'a> State<'a> {
21742174
match decl.output {
21752175
hir::FnRetTy::Return(ref ty) => {
21762176
self.print_type(&ty);
2177-
self.maybe_print_comment(ty.span.lo())
2177+
self.maybe_print_comment(ty.span.lo());
21782178
}
21792179
hir::FnRetTy::DefaultReturn(..) => unreachable!(),
21802180
}
@@ -2368,7 +2368,7 @@ impl<'a> State<'a> {
23682368
self.end();
23692369

23702370
if let hir::FnRetTy::Return(ref output) = decl.output {
2371-
self.maybe_print_comment(output.span.lo())
2371+
self.maybe_print_comment(output.span.lo());
23722372
}
23732373
}
23742374

Diff for: compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,6 @@ fn test_debugging_options_tracking_hash() {
651651
untracked!(dump_mir_dir, String::from("abc"));
652652
untracked!(dump_mir_exclude_pass_number, true);
653653
untracked!(dump_mir_graphviz, true);
654-
untracked!(emit_future_incompat_report, true);
655654
untracked!(emit_stack_sizes, true);
656655
untracked!(future_incompat_test, true);
657656
untracked!(hir_stats, true);

Diff for: compiler/rustc_session/src/config.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ impl Default for Options {
746746
edition: DEFAULT_EDITION,
747747
json_artifact_notifications: false,
748748
json_unused_externs: false,
749+
json_future_incompat: false,
749750
pretty: None,
750751
working_dir: RealFileName::LocalPath(std::env::current_dir().unwrap()),
751752
}
@@ -1257,6 +1258,7 @@ pub struct JsonConfig {
12571258
pub json_rendered: HumanReadableErrorType,
12581259
pub json_artifact_notifications: bool,
12591260
pub json_unused_externs: bool,
1261+
pub json_future_incompat: bool,
12601262
}
12611263

12621264
/// Parse the `--json` flag.
@@ -1269,6 +1271,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
12691271
let mut json_color = ColorConfig::Never;
12701272
let mut json_artifact_notifications = false;
12711273
let mut json_unused_externs = false;
1274+
let mut json_future_incompat = false;
12721275
for option in matches.opt_strs("json") {
12731276
// For now conservatively forbid `--color` with `--json` since `--json`
12741277
// won't actually be emitting any colors and anything colorized is
@@ -1286,6 +1289,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
12861289
"diagnostic-rendered-ansi" => json_color = ColorConfig::Always,
12871290
"artifacts" => json_artifact_notifications = true,
12881291
"unused-externs" => json_unused_externs = true,
1292+
"future-incompat" => json_future_incompat = true,
12891293
s => early_error(
12901294
ErrorOutputType::default(),
12911295
&format!("unknown `--json` option `{}`", s),
@@ -1298,6 +1302,7 @@ pub fn parse_json(matches: &getopts::Matches) -> JsonConfig {
12981302
json_rendered: json_rendered(json_color),
12991303
json_artifact_notifications,
13001304
json_unused_externs,
1305+
json_future_incompat,
13011306
}
13021307
}
13031308

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

20122017
let edition = parse_crate_edition(matches);
20132018

2014-
let JsonConfig { json_rendered, json_artifact_notifications, json_unused_externs } =
2015-
parse_json(matches);
2019+
let JsonConfig {
2020+
json_rendered,
2021+
json_artifact_notifications,
2022+
json_unused_externs,
2023+
json_future_incompat,
2024+
} = parse_json(matches);
20162025

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

@@ -2248,6 +2257,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
22482257
edition,
22492258
json_artifact_notifications,
22502259
json_unused_externs,
2260+
json_future_incompat,
22512261
pretty,
22522262
working_dir,
22532263
}

Diff for: compiler/rustc_session/src/options.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ top_level_options!(
228228
/// `true` if we're emitting a JSON blob containing the unused externs
229229
json_unused_externs: bool [UNTRACKED],
230230

231+
/// `true` if we're emitting a JSON job containg a future-incompat report for lints
232+
json_future_incompat: bool [TRACKED],
233+
231234
pretty: Option<PpMode> [UNTRACKED],
232235

233236
/// The (potentially remapped) working directory
@@ -1147,8 +1150,6 @@ options! {
11471150
computed `block` spans (one span encompassing a block's terminator and \
11481151
all statements). If `-Z instrument-coverage` is also enabled, create \
11491152
an additional `.html` file showing the computed coverage spans."),
1150-
emit_future_incompat_report: bool = (false, parse_bool, [UNTRACKED],
1151-
"emits a future-incompatibility report for lints (RFC 2834)"),
11521153
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
11531154
"emit a section containing stack size metadata (default: no)"),
11541155
fewer_names: Option<bool> = (None, parse_opt_bool, [TRACKED],

Diff for: compiler/rustc_session/src/session.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ impl Session {
280280
}
281281

282282
fn emit_future_breakage(&self) {
283-
if !self.opts.debugging_opts.emit_future_incompat_report {
283+
if !self.opts.json_future_incompat {
284284
return;
285285
}
286286

Diff for: compiler/rustc_trait_selection/src/traits/const_evaluatable.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,25 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
399399
let arg = self.recurse_build(source)?;
400400
self.nodes.push(Node::Cast(abstract_const::CastKind::As, arg, node.ty))
401401
}
402-
402+
ExprKind::Borrow{ arg, ..} => {
403+
let arg_node = &self.body.exprs[*arg];
404+
405+
// Skip reborrows for now until we allow Deref/Borrow/AddressOf
406+
// expressions.
407+
// FIXME(generic_const_exprs): Verify/explain why this is sound
408+
if let ExprKind::Deref {arg} = arg_node.kind {
409+
self.recurse_build(arg)?
410+
} else {
411+
self.maybe_supported_error(
412+
node.span,
413+
"borrowing is not supported in generic constants",
414+
)?
415+
}
416+
}
403417
// FIXME(generic_const_exprs): We may want to support these.
404-
ExprKind::AddressOf { .. }
405-
| ExprKind::Borrow { .. }
406-
| ExprKind::Deref { .. } => self.maybe_supported_error(
418+
ExprKind::AddressOf { .. } | ExprKind::Deref {..}=> self.maybe_supported_error(
407419
node.span,
408-
"dereferencing is not supported in generic constants",
420+
"dereferencing or taking the address is not supported in generic constants",
409421
)?,
410422
ExprKind::Repeat { .. } | ExprKind::Array { .. } => self.maybe_supported_error(
411423
node.span,

Diff for: compiler/rustc_typeck/src/collect.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc_middle::ty::subst::InternalSubsts;
4141
use rustc_middle::ty::util::Discr;
4242
use rustc_middle::ty::util::IntTypeExt;
4343
use rustc_middle::ty::{self, AdtKind, Const, DefIdTree, Ty, TyCtxt};
44-
use rustc_middle::ty::{ReprOptions, ToPredicate, WithConstness};
44+
use rustc_middle::ty::{ReprOptions, ToPredicate, TypeFoldable, WithConstness};
4545
use rustc_session::lint;
4646
use rustc_session::parse::feature_err;
4747
use rustc_span::symbol::{kw, sym, Ident, Symbol};
@@ -1777,7 +1777,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
17771777
visitor.visit_ty(ty);
17781778
let mut diag = bad_placeholder_type(tcx, visitor.0, "return type");
17791779
let ret_ty = fn_sig.skip_binder().output();
1780-
if ret_ty != tcx.ty_error() {
1780+
if !ret_ty.references_error() {
17811781
if !ret_ty.is_closure() {
17821782
let ret_ty_str = match ret_ty.kind() {
17831783
// Suggest a function pointer return type instead of a unique function definition

Diff for: src/test/pretty/ast-stmt-expr-attr.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// pp-exact
22

3-
fn main() { }
3+
fn main() {}
44

55
#[cfg(FALSE)]
66
fn syntax() {
@@ -117,7 +117,7 @@ fn syntax() {
117117
let _ = #[attr] foo!(#! [attr]);
118118
let _ = #[attr] foo![];
119119
let _ = #[attr] foo![#! [attr]];
120-
let _ = #[attr] foo! { };
120+
let _ = #[attr] foo! {};
121121
let _ = #[attr] foo! { #! [attr] };
122122
let _ = #[attr] Foo{bar: baz,};
123123
let _ = #[attr] Foo{..foo};
@@ -135,7 +135,7 @@ fn syntax() {
135135
foo!();
136136

137137
#[attr]
138-
foo! { }
138+
foo! {}
139139

140140
#[attr]
141141
foo![];
@@ -170,6 +170,6 @@ fn syntax() {
170170
{
171171

172172
#[attr]
173-
foo! { }
173+
foo! {}
174174
}
175175
}

Diff for: src/test/pretty/attr-derive.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ enum Enum {
2929
Qwerty,
3030
}
3131

32-
fn main() { }
32+
fn main() {}

Diff for: src/test/pretty/auto-trait.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
// pp-exact
44

5-
auto trait MyTrait { }
5+
auto trait MyTrait {}
66

7-
unsafe auto trait UnsafeMyTrait { }
7+
unsafe auto trait UnsafeMyTrait {}
88

9-
pub fn main() { }
9+
pub fn main() {}
+4-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
// compile-flags: --crate-type=lib
22

33
// pp-exact
4-
fn f() {
5-
} /*
6-
The next line should not be indented.
4+
fn f() {} /*
5+
The next line should not be indented.
76
8-
That one. It shouldn't have been indented.
9-
*/
7+
That one. It shouldn't have been indented.
8+
*/

0 commit comments

Comments
 (0)