Skip to content

Commit e069a71

Browse files
committed
Auto merge of rust-lang#93689 - matthiaskrgr:rollup-3pd1ept, r=matthiaskrgr
Rollup of 9 pull requests Successful merges: - rust-lang#91939 (Clarify error on casting larger integers to char) - rust-lang#92300 (mips64-openwrt-linux-musl: Add Tier 3 target) - rust-lang#92383 (Add new target armv7-unknown-linux-uclibceabi (softfloat)) - rust-lang#92651 (Remove "up here" arrow on item-infos) - rust-lang#93556 (Change struct expr pretty printing to match rustfmt style) - rust-lang#93649 (Add regression tests for issue 80309) - rust-lang#93657 (Update CPU idle tracking for apple hosts) - rust-lang#93659 (Refactor conditional) - rust-lang#93669 (Resolve lifetimes for const generic defaults) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 719b04c + cbf4b46 commit e069a71

36 files changed

+522
-131
lines changed

compiler/rustc_ast_pretty/src/pp.rs

+17-5
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub enum Breaks {
148148
Inconsistent,
149149
}
150150

151-
#[derive(Clone, Copy)]
151+
#[derive(Clone, Copy, PartialEq)]
152152
enum IndentStyle {
153153
/// Vertically aligned under whatever column this block begins at.
154154
///
@@ -164,19 +164,20 @@ enum IndentStyle {
164164
Block { offset: isize },
165165
}
166166

167-
#[derive(Clone, Copy)]
167+
#[derive(Clone, Copy, Default, PartialEq)]
168168
pub struct BreakToken {
169169
offset: isize,
170170
blank_space: isize,
171+
pre_break: Option<char>,
171172
}
172173

173-
#[derive(Clone, Copy)]
174+
#[derive(Clone, Copy, PartialEq)]
174175
pub struct BeginToken {
175176
indent: IndentStyle,
176177
breaks: Breaks,
177178
}
178179

179-
#[derive(Clone)]
180+
#[derive(Clone, PartialEq)]
180181
pub enum Token {
181182
// In practice a string token contains either a `&'static str` or a
182183
// `String`. `Cow` is overkill for this because we never modify the data,
@@ -313,6 +314,12 @@ impl Printer {
313314
}
314315
}
315316

317+
pub fn offset(&mut self, offset: isize) {
318+
if let Some(BufEntry { token: Token::Break(token), .. }) = &mut self.buf.last_mut() {
319+
token.offset += offset;
320+
}
321+
}
322+
316323
fn check_stream(&mut self) {
317324
while self.right_total - self.left_total > self.space {
318325
if *self.scan_stack.front().unwrap() == self.buf.index_of_first() {
@@ -391,7 +398,9 @@ impl Printer {
391398
if size > self.space {
392399
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
393400
self.indent = match token.indent {
394-
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
401+
IndentStyle::Block { offset } => {
402+
usize::try_from(self.indent as isize + offset).unwrap()
403+
}
395404
IndentStyle::Visual => (MARGIN - self.space) as usize,
396405
};
397406
} else {
@@ -415,6 +424,9 @@ impl Printer {
415424
self.pending_indentation += token.blank_space;
416425
self.space -= token.blank_space;
417426
} else {
427+
if let Some(pre_break) = token.pre_break {
428+
self.out.push(pre_break);
429+
}
418430
self.out.push('\n');
419431
let indent = self.indent as isize + token.offset;
420432
self.pending_indentation = indent;

compiler/rustc_ast_pretty/src/pp/convenience.rs

+23-10
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,17 @@ use std::borrow::Cow;
33

44
impl Printer {
55
/// "raw box"
6-
pub fn rbox(&mut self, indent: usize, breaks: Breaks) {
7-
self.scan_begin(BeginToken {
8-
indent: IndentStyle::Block { offset: indent as isize },
9-
breaks,
10-
})
6+
pub fn rbox(&mut self, indent: isize, breaks: Breaks) {
7+
self.scan_begin(BeginToken { indent: IndentStyle::Block { offset: indent }, breaks })
118
}
129

1310
/// Inconsistent breaking box
14-
pub fn ibox(&mut self, indent: usize) {
11+
pub fn ibox(&mut self, indent: isize) {
1512
self.rbox(indent, Breaks::Inconsistent)
1613
}
1714

1815
/// Consistent breaking box
19-
pub fn cbox(&mut self, indent: usize) {
16+
pub fn cbox(&mut self, indent: isize) {
2017
self.rbox(indent, Breaks::Consistent)
2118
}
2219

@@ -25,7 +22,11 @@ impl Printer {
2522
}
2623

2724
pub fn break_offset(&mut self, n: usize, off: isize) {
28-
self.scan_break(BreakToken { offset: off, blank_space: n as isize })
25+
self.scan_break(BreakToken {
26+
offset: off,
27+
blank_space: n as isize,
28+
..BreakToken::default()
29+
});
2930
}
3031

3132
pub fn end(&mut self) {
@@ -66,12 +67,24 @@ impl Printer {
6667
}
6768

6869
pub fn hardbreak_tok_offset(off: isize) -> Token {
69-
Token::Break(BreakToken { offset: off, blank_space: SIZE_INFINITY })
70+
Token::Break(BreakToken {
71+
offset: off,
72+
blank_space: SIZE_INFINITY,
73+
..BreakToken::default()
74+
})
75+
}
76+
77+
pub fn trailing_comma(&mut self) {
78+
self.scan_break(BreakToken {
79+
blank_space: 1,
80+
pre_break: Some(','),
81+
..BreakToken::default()
82+
});
7083
}
7184
}
7285

7386
impl Token {
7487
pub fn is_hardbreak_tok(&self) -> bool {
75-
matches!(self, Token::Break(BreakToken { offset: 0, blank_space: SIZE_INFINITY }))
88+
*self == Printer::hardbreak_tok_offset(0)
7689
}
7790
}

compiler/rustc_ast_pretty/src/pprust/state.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
mod delimited;
12
mod expr;
23
mod item;
34

@@ -23,6 +24,8 @@ use rustc_span::{BytePos, FileName, Span};
2324

2425
use std::borrow::Cow;
2526

27+
pub use self::delimited::IterDelimited;
28+
2629
pub enum MacHeader<'a> {
2730
Path(&'a ast::Path),
2831
Keyword(&'static str),
@@ -92,7 +95,7 @@ pub struct State<'a> {
9295
ann: &'a (dyn PpAnn + 'a),
9396
}
9497

95-
crate const INDENT_UNIT: usize = 4;
98+
crate const INDENT_UNIT: isize = 4;
9699

97100
/// Requires you to pass an input filename and reader so that
98101
/// it can scan the input text for comments to copy forward.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
use std::iter::Peekable;
2+
use std::mem;
3+
use std::ops::Deref;
4+
5+
pub struct Delimited<I: Iterator> {
6+
is_first: bool,
7+
iter: Peekable<I>,
8+
}
9+
10+
pub trait IterDelimited: Iterator + Sized {
11+
fn delimited(self) -> Delimited<Self> {
12+
Delimited { is_first: true, iter: self.peekable() }
13+
}
14+
}
15+
16+
impl<I: Iterator> IterDelimited for I {}
17+
18+
pub struct IteratorItem<T> {
19+
value: T,
20+
pub is_first: bool,
21+
pub is_last: bool,
22+
}
23+
24+
impl<I: Iterator> Iterator for Delimited<I> {
25+
type Item = IteratorItem<I::Item>;
26+
27+
fn next(&mut self) -> Option<Self::Item> {
28+
let value = self.iter.next()?;
29+
let is_first = mem::replace(&mut self.is_first, false);
30+
let is_last = self.iter.peek().is_none();
31+
Some(IteratorItem { value, is_first, is_last })
32+
}
33+
}
34+
35+
impl<T> Deref for IteratorItem<T> {
36+
type Target = T;
37+
38+
fn deref(&self) -> &Self::Target {
39+
&self.value
40+
}
41+
}

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

+39-31
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::pp::Breaks::{Consistent, Inconsistent};
2-
use crate::pprust::state::{AnnNode, PrintState, State, INDENT_UNIT};
1+
use crate::pp::Breaks::Inconsistent;
2+
use crate::pprust::state::{AnnNode, IterDelimited, PrintState, State, INDENT_UNIT};
33

44
use rustc_ast::ptr::P;
55
use rustc_ast::util::parser::{self, AssocOp, Fixity};
@@ -117,38 +117,46 @@ impl<'a> State<'a> {
117117
} else {
118118
self.print_path(path, true, 0);
119119
}
120+
self.nbsp();
120121
self.word("{");
121-
self.commasep_cmnt(
122-
Consistent,
123-
fields,
124-
|s, field| {
125-
s.print_outer_attributes(&field.attrs);
126-
s.ibox(INDENT_UNIT);
127-
if !field.is_shorthand {
128-
s.print_ident(field.ident);
129-
s.word_space(":");
130-
}
131-
s.print_expr(&field.expr);
132-
s.end();
133-
},
134-
|f| f.span,
135-
);
136-
match rest {
137-
ast::StructRest::Base(_) | ast::StructRest::Rest(_) => {
138-
self.ibox(INDENT_UNIT);
139-
if !fields.is_empty() {
140-
self.word(",");
141-
self.space();
142-
}
143-
self.word("..");
144-
if let ast::StructRest::Base(ref expr) = *rest {
145-
self.print_expr(expr);
146-
}
147-
self.end();
122+
let has_rest = match rest {
123+
ast::StructRest::Base(_) | ast::StructRest::Rest(_) => true,
124+
ast::StructRest::None => false,
125+
};
126+
if fields.is_empty() && !has_rest {
127+
self.word("}");
128+
return;
129+
}
130+
self.cbox(0);
131+
for field in fields.iter().delimited() {
132+
self.maybe_print_comment(field.span.hi());
133+
self.print_outer_attributes(&field.attrs);
134+
if field.is_first {
135+
self.space_if_not_bol();
136+
}
137+
if !field.is_shorthand {
138+
self.print_ident(field.ident);
139+
self.word_nbsp(":");
140+
}
141+
self.print_expr(&field.expr);
142+
if !field.is_last || has_rest {
143+
self.word_space(",");
144+
} else {
145+
self.trailing_comma();
148146
}
149-
ast::StructRest::None if !fields.is_empty() => self.word(","),
150-
_ => {}
151147
}
148+
if has_rest {
149+
if fields.is_empty() {
150+
self.space();
151+
}
152+
self.word("..");
153+
if let ast::StructRest::Base(expr) = rest {
154+
self.print_expr(expr);
155+
}
156+
self.space();
157+
}
158+
self.offset(-INDENT_UNIT);
159+
self.end();
152160
self.word("}");
153161
}
154162

compiler/rustc_error_codes/src/error_codes/E0604.md

+8-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@ Erroneous code example:
66
0u32 as char; // error: only `u8` can be cast as `char`, not `u32`
77
```
88

9-
As the error message indicates, only `u8` can be cast into `char`. Example:
9+
`char` is a Unicode Scalar Value, an integer value from 0 to 0xD7FF and
10+
0xE000 to 0x10FFFF. (The gap is for surrogate pairs.) Only `u8` always fits in
11+
those ranges so only `u8` may be cast to `char`.
12+
13+
To allow larger values, use `char::from_u32`, which checks the value is valid.
1014

1115
```
12-
let c = 86u8 as char; // ok!
13-
assert_eq!(c, 'V');
16+
assert_eq!(86u8 as char, 'V'); // ok!
17+
assert_eq!(char::from_u32(0x3B1), Some('α')); // ok!
18+
assert_eq!(char::from_u32(0xD800), None); // not a USV.
1419
```
1520

1621
For more information about casts, take a look at the Type cast section in

compiler/rustc_hir_pretty/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ impl<'a> PrintState<'a> for State<'a> {
139139
}
140140
}
141141

142-
pub const INDENT_UNIT: usize = 4;
142+
pub const INDENT_UNIT: isize = 4;
143143

144144
/// Requires you to pass an input filename and reader so that
145145
/// it can scan the input text for comments to copy forward.

compiler/rustc_resolve/src/late/lifetimes.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1339,11 +1339,14 @@ impl<'a, 'tcx> Visitor<'tcx> for LifetimeContext<'a, 'tcx> {
13391339
this.visit_ty(&ty);
13401340
}
13411341
}
1342-
GenericParamKind::Const { ref ty, .. } => {
1342+
GenericParamKind::Const { ref ty, default } => {
13431343
let was_in_const_generic = this.is_in_const_generic;
13441344
this.is_in_const_generic = true;
13451345
walk_list!(this, visit_param_bound, param.bounds);
13461346
this.visit_ty(&ty);
1347+
if let Some(default) = default {
1348+
this.visit_body(this.tcx.hir().body(default.body));
1349+
}
13471350
this.is_in_const_generic = was_in_const_generic;
13481351
}
13491352
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::spec::{Target, TargetOptions};
2+
3+
// This target is for uclibc Linux on ARMv7 without NEON,
4+
// thumb-mode or hardfloat.
5+
6+
pub fn target() -> Target {
7+
let base = super::linux_uclibc_base::opts();
8+
Target {
9+
llvm_target: "armv7-unknown-linux-gnueabi".to_string(),
10+
pointer_width: 32,
11+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
12+
arch: "arm".to_string(),
13+
14+
options: TargetOptions {
15+
features: "+v7,+thumb2,+soft-float,-neon".to_string(),
16+
cpu: "generic".to_string(),
17+
max_atomic_width: Some(64),
18+
mcount: "_mcount".to_string(),
19+
abi: "eabi".to_string(),
20+
..base
21+
},
22+
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// A target tuple for OpenWrt MIPS64 targets
2+
///
3+
use crate::abi::Endian;
4+
use crate::spec::{Target, TargetOptions};
5+
6+
pub fn target() -> Target {
7+
let mut base = super::linux_musl_base::opts();
8+
base.cpu = "mips64r2".to_string();
9+
base.features = "+mips64r2".to_string();
10+
base.max_atomic_width = Some(64);
11+
base.crt_static_default = false;
12+
13+
Target {
14+
// LLVM doesn't recognize "muslabi64" yet.
15+
llvm_target: "mips64-unknown-linux-musl".to_string(),
16+
pointer_width: 64,
17+
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-n32:64-S128".to_string(),
18+
arch: "mips64".to_string(),
19+
options: TargetOptions {
20+
abi: "abi64".to_string(),
21+
endian: Endian::Big,
22+
mcount: "_mcount".to_string(),
23+
..base
24+
},
25+
}
26+
}

compiler/rustc_target/src/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1013,9 +1013,12 @@ supported_targets! {
10131013

10141014
("armv6k-nintendo-3ds", armv6k_nintendo_3ds),
10151015

1016+
("armv7-unknown-linux-uclibceabi", armv7_unknown_linux_uclibceabi),
10161017
("armv7-unknown-linux-uclibceabihf", armv7_unknown_linux_uclibceabihf),
10171018

10181019
("x86_64-unknown-none", x86_64_unknown_none),
1020+
1021+
("mips64-openwrt-linux-musl", mips64_openwrt_linux_musl),
10191022
}
10201023

10211024
/// Warnings encountered when parsing the target `json`.

0 commit comments

Comments
 (0)