Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit cb31a00

Browse files
committed
Auto merge of #140366 - matthiaskrgr:rollup-zd3q1oy, r=matthiaskrgr
Rollup of 4 pull requests Successful merges: - #140246 (Fix never pattern printing) - #140280 (Improve if/else pretty printing) - #140348 (Update lint-docs to default to Rust 2024) - #140358 (Use `search_for_cycle_permutation` to look for `variances_of`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 267cae5 + fdfc7c0 commit cb31a00

File tree

16 files changed

+368
-108
lines changed

16 files changed

+368
-108
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ impl<'a> State<'a> {
2121
match &_else.kind {
2222
// Another `else if` block.
2323
ast::ExprKind::If(i, then, e) => {
24-
self.cbox(INDENT_UNIT - 1);
24+
self.cbox(0);
2525
self.ibox(0);
2626
self.word(" else if ");
2727
self.print_expr_as_cond(i);
@@ -30,8 +30,8 @@ impl<'a> State<'a> {
3030
self.print_else(e.as_deref())
3131
}
3232
// Final `else` block.
33-
ast::ExprKind::Block(b, _) => {
34-
self.cbox(INDENT_UNIT - 1);
33+
ast::ExprKind::Block(b, None) => {
34+
self.cbox(0);
3535
self.ibox(0);
3636
self.word(" else ");
3737
self.print_block(b)
@@ -45,7 +45,9 @@ impl<'a> State<'a> {
4545
}
4646

4747
fn print_if(&mut self, test: &ast::Expr, blk: &ast::Block, elseopt: Option<&ast::Expr>) {
48-
self.head("if");
48+
self.cbox(0);
49+
self.ibox(0);
50+
self.word_nbsp("if");
4951
self.print_expr_as_cond(test);
5052
self.space();
5153
self.print_block(blk);
@@ -876,6 +878,7 @@ impl<'a> State<'a> {
876878
}
877879
}
878880
} else {
881+
self.end(); // Close the ibox for the pattern.
879882
self.word(",");
880883
}
881884
self.end(); // Close enclosing cbox.

‎compiler/rustc_hir_pretty/src/lib.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,18 +1064,18 @@ impl<'a> State<'a> {
10641064
if let Some(els_inner) = els {
10651065
match els_inner.kind {
10661066
// Another `else if` block.
1067-
hir::ExprKind::If(i, then, e) => {
1068-
self.cbox(INDENT_UNIT - 1);
1067+
hir::ExprKind::If(i, hir::Expr{kind: hir::ExprKind::Block(t,None), .. }, e) => {
1068+
self.cbox(0);
10691069
self.ibox(0);
10701070
self.word(" else if ");
10711071
self.print_expr_as_cond(i);
10721072
self.space();
1073-
self.print_expr(then);
1073+
self.print_block(t);
10741074
self.print_else(e);
10751075
}
10761076
// Final `else` block.
1077-
hir::ExprKind::Block(b, _) => {
1078-
self.cbox(INDENT_UNIT - 1);
1077+
hir::ExprKind::Block(b, None) => {
1078+
self.cbox(0);
10791079
self.ibox(0);
10801080
self.word(" else ");
10811081
self.print_block(b);
@@ -1094,11 +1094,18 @@ impl<'a> State<'a> {
10941094
blk: &hir::Expr<'_>,
10951095
elseopt: Option<&hir::Expr<'_>>,
10961096
) {
1097-
self.head("if");
1097+
self.cbox(0);
1098+
self.ibox(0);
1099+
self.word_nbsp("if");
10981100
self.print_expr_as_cond(test);
10991101
self.space();
1100-
self.print_expr(blk);
1101-
self.print_else(elseopt)
1102+
match blk.kind {
1103+
hir::ExprKind::Block(blk, None) => {
1104+
self.print_block(blk);
1105+
self.print_else(elseopt)
1106+
}
1107+
_ => panic!("non-block then expr"),
1108+
}
11021109
}
11031110

11041111
fn print_anon_const(&mut self, constant: &hir::AnonConst) {

‎compiler/rustc_lint/src/builtin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -948,7 +948,7 @@ declare_lint! {
948948
///
949949
/// ### Example
950950
///
951-
/// ```rust,compile_fail
951+
/// ```rust,compile_fail,edition2021
952952
/// #[no_mangle]
953953
/// const FOO: i32 = 5;
954954
/// ```

‎compiler/rustc_lint/src/impl_trait_overcaptures.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ declare_lint! {
4141
///
4242
/// ### Example
4343
///
44-
/// ```rust,compile_fail
44+
/// ```rust,compile_fail,edition2021
4545
/// # #![deny(impl_trait_overcaptures)]
4646
/// # use std::fmt::Display;
4747
/// let mut x = vec![];

‎compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1424,7 +1424,7 @@ declare_lint! {
14241424
///
14251425
/// ### Example
14261426
///
1427-
/// ```rust,compile_fail
1427+
/// ```rust,compile_fail,edition2021
14281428
/// macro_rules! foo {
14291429
/// () => {};
14301430
/// ($name) => { };
@@ -4128,7 +4128,7 @@ declare_lint! {
41284128
///
41294129
/// ### Example
41304130
///
4131-
/// ```rust,compile_fail
4131+
/// ```rust,compile_fail,edition2021
41324132
/// #![deny(dependency_on_unit_never_type_fallback)]
41334133
/// fn main() {
41344134
/// if true {

‎compiler/rustc_middle/src/values.rs

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -138,18 +138,26 @@ impl<'tcx> Value<TyCtxt<'tcx>> for &[ty::Variance] {
138138
cycle_error: &CycleError,
139139
_guar: ErrorGuaranteed,
140140
) -> Self {
141-
if let Some(frame) = cycle_error.cycle.get(0)
142-
&& frame.query.dep_kind == dep_kinds::variances_of
143-
&& let Some(def_id) = frame.query.def_id
144-
{
145-
let n = tcx.generics_of(def_id).own_params.len();
146-
vec![ty::Bivariant; n].leak()
147-
} else {
148-
span_bug!(
149-
cycle_error.usage.as_ref().unwrap().0,
150-
"only `variances_of` returns `&[ty::Variance]`"
151-
);
152-
}
141+
search_for_cycle_permutation(
142+
&cycle_error.cycle,
143+
|cycle| {
144+
if let Some(frame) = cycle.get(0)
145+
&& frame.query.dep_kind == dep_kinds::variances_of
146+
&& let Some(def_id) = frame.query.def_id
147+
{
148+
let n = tcx.generics_of(def_id).own_params.len();
149+
ControlFlow::Break(vec![ty::Bivariant; n].leak())
150+
} else {
151+
ControlFlow::Continue(())
152+
}
153+
},
154+
|| {
155+
span_bug!(
156+
cycle_error.usage.as_ref().unwrap().0,
157+
"only `variances_of` returns `&[ty::Variance]`"
158+
)
159+
},
160+
)
153161
}
154162
}
155163

‎src/tools/lint-docs/src/lib.rs

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -444,21 +444,15 @@ impl<'a> LintExtractor<'a> {
444444
fs::write(&tempfile, source)
445445
.map_err(|e| format!("failed to write {}: {}", tempfile.display(), e))?;
446446
let mut cmd = Command::new(self.rustc_path);
447-
if options.contains(&"edition2024") {
448-
cmd.arg("--edition=2024");
449-
cmd.arg("-Zunstable-options");
450-
} else if options.contains(&"edition2021") {
451-
cmd.arg("--edition=2021");
452-
} else if options.contains(&"edition2018") {
453-
cmd.arg("--edition=2018");
454-
} else if options.contains(&"edition2015") {
455-
cmd.arg("--edition=2015");
456-
} else if options.contains(&"edition") {
457-
panic!("lint-docs: unknown edition");
458-
} else {
447+
let edition = options
448+
.iter()
449+
.filter_map(|opt| opt.strip_prefix("edition"))
450+
.next()
459451
// defaults to latest edition
460-
cmd.arg("--edition=2021");
461-
}
452+
.unwrap_or("2024");
453+
cmd.arg(format!("--edition={edition}"));
454+
// Just in case this is an unstable edition.
455+
cmd.arg("-Zunstable-options");
462456
cmd.arg("--error-format=json");
463457
cmd.arg("--target").arg(self.rustc_target);
464458
if let Some(target_linker) = self.rustc_linker {

‎tests/pretty/hir-if-else.pp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#[prelude_import]
2+
use ::std::prelude::rust_2015::*;
3+
#[macro_use]
4+
extern crate std;
5+
//@ pretty-compare-only
6+
//@ pretty-mode:hir
7+
//@ pp-exact:hir-if-else.pp
8+
9+
fn f(x: u32,
10+
y:
11+
u32) {
12+
let mut a = 0;
13+
if x > y { a = 1; } else { a = 2; }
14+
15+
if x < 1 {
16+
a = 1;
17+
} else if x < 2 {
18+
a = 2;
19+
} else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; }
20+
21+
if x < y {
22+
a += 1;
23+
a += 1;
24+
a += 1;
25+
a += 1;
26+
a += 1;
27+
a += 1;
28+
} else { a += 1; a += 1; a += 1; a += 1; a += 1; a += 1; }
29+
30+
if x < 1 {
31+
if x < 2 {
32+
if x < 3 {
33+
a += 1;
34+
} else if x < 4 { a += 1; if x < 5 { a += 1; } }
35+
} else if x < 6 { a += 1; }
36+
}
37+
}
38+
39+
fn main() { f(3, 4); }

‎tests/pretty/hir-if-else.rs

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
//@ pretty-compare-only
2+
//@ pretty-mode:hir
3+
//@ pp-exact:hir-if-else.pp
4+
5+
fn f(x: u32, y: u32) {
6+
let mut a = 0;
7+
if x > y {
8+
a = 1;
9+
} else {
10+
a = 2;
11+
}
12+
13+
if x < 1 {
14+
a = 1;
15+
} else if x < 2 {
16+
a = 2;
17+
} else if x < 3 {
18+
a = 3;
19+
} else if x < 4 {
20+
a = 4;
21+
} else {
22+
a = 5;
23+
}
24+
25+
if x < y {
26+
a += 1;
27+
a += 1;
28+
a += 1;
29+
a += 1;
30+
a += 1;
31+
a += 1;
32+
} else {
33+
a += 1;
34+
a += 1;
35+
a += 1;
36+
a += 1;
37+
a += 1;
38+
a += 1;
39+
}
40+
41+
if x < 1 {
42+
if x < 2 {
43+
if x < 3 {
44+
a += 1;
45+
} else if x < 4 {
46+
a += 1;
47+
if x < 5 {
48+
a += 1;
49+
}
50+
}
51+
} else if x < 6 {
52+
a += 1;
53+
}
54+
}
55+
}
56+
57+
fn main() {
58+
f(3, 4);
59+
}

‎tests/pretty/if-else.pp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#![feature(prelude_import)]
2+
#![no_std]
3+
#[prelude_import]
4+
use ::std::prelude::rust_2015::*;
5+
#[macro_use]
6+
extern crate std;
7+
//@ pretty-compare-only
8+
//@ pretty-mode:expanded
9+
//@ pp-exact:if-else.pp
10+
11+
fn f(x: u32, y: u32) {
12+
let mut a = 0;
13+
if x > y { a = 1; } else { a = 2; }
14+
15+
if x < 1 {
16+
a = 1;
17+
} else if x < 2 {
18+
a = 2;
19+
} else if x < 3 { a = 3; } else if x < 4 { a = 4; } else { a = 5; }
20+
21+
if x < y {
22+
a += 1;
23+
a += 1;
24+
a += 1;
25+
} else {
26+
a += 1;
27+
a += 1;
28+
a += 1;
29+
a += 1;
30+
a += 1;
31+
a += 1;
32+
a += 1;
33+
a += 1;
34+
a += 1;
35+
a += 1;
36+
a += 1;
37+
a += 1;
38+
a += 1;
39+
a += 1;
40+
a += 1;
41+
}
42+
43+
if x < 1 {
44+
if x < 2 {
45+
if x < 3 {
46+
a += 1;
47+
} else if x < 4 { a += 1; if x < 5 { a += 1; } }
48+
} else if x < 6 { a += 1; }
49+
}
50+
}
51+
52+
fn main() { f(3, 4); }

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /