Skip to content

Commit 93e8201

Browse files
committed
Auto merge of rust-lang#93534 - ehuss:rollup-9ecozo9, r=ehuss
Rollup of 9 pull requests Successful merges: - rust-lang#91343 (Fix suggestion to slice if scrutinee is a `Result` or `Option`) - rust-lang#93019 (If an integer is entered with an upper-case base prefix (0Xbeef, 0O755, 0B1010), suggest to make it lowercase) - rust-lang#93090 (`impl Display for io::ErrorKind`) - rust-lang#93456 (Remove an unnecessary transmute from opaque::Encoder) - rust-lang#93492 (Hide failed command unless in verbose mode) - rust-lang#93504 (kmc-solid: Increase the default stack size) - rust-lang#93513 (Allow any pretty printed line to have at least 60 chars) - rust-lang#93532 (Update books) - rust-lang#93533 (Update cargo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 25862ff + 81900f4 commit 93e8201

File tree

24 files changed

+467
-44
lines changed

24 files changed

+467
-44
lines changed

Cargo.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ dependencies = [
337337
"cargo-test-macro",
338338
"cargo-test-support",
339339
"cargo-util",
340-
"clap 3.0.10",
340+
"clap 3.0.13",
341341
"crates-io",
342342
"crossbeam-utils",
343343
"curl",
@@ -627,9 +627,9 @@ dependencies = [
627627

628628
[[package]]
629629
name = "clap"
630-
version = "3.0.10"
630+
version = "3.0.13"
631631
source = "registry+https://github.com/rust-lang/crates.io-index"
632-
checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375"
632+
checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e"
633633
dependencies = [
634634
"atty",
635635
"bitflags",
@@ -5233,9 +5233,9 @@ dependencies = [
52335233

52345234
[[package]]
52355235
name = "toml_edit"
5236-
version = "0.13.0"
5236+
version = "0.13.4"
52375237
source = "registry+https://github.com/rust-lang/crates.io-index"
5238-
checksum = "3b80ac5e1b91e3378c63dab121962472b5ca20cf9ab1975e3d588548717807a8"
5238+
checksum = "744e9ed5b352340aa47ce033716991b5589e23781acb97cad37d4ea70560f55b"
52395239
dependencies = [
52405240
"combine",
52415241
"indexmap",

compiler/rustc_ast_pretty/src/pp.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ mod ring;
136136

137137
use ring::RingBuffer;
138138
use std::borrow::Cow;
139+
use std::cmp;
139140
use std::collections::VecDeque;
140141
use std::iter;
141142

@@ -199,10 +200,13 @@ enum PrintFrame {
199200

200201
const SIZE_INFINITY: isize = 0xffff;
201202

203+
/// Target line width.
204+
const MARGIN: isize = 78;
205+
/// Every line is allowed at least this much space, even if highly indented.
206+
const MIN_SPACE: isize = 60;
207+
202208
pub struct Printer {
203209
out: String,
204-
/// Width of lines we're constrained to
205-
margin: isize,
206210
/// Number of spaces left on line
207211
space: isize,
208212
/// Ring-buffer of tokens and calculated sizes
@@ -237,11 +241,9 @@ struct BufEntry {
237241

238242
impl Printer {
239243
pub fn new() -> Self {
240-
let linewidth = 78;
241244
Printer {
242245
out: String::new(),
243-
margin: linewidth as isize,
244-
space: linewidth as isize,
246+
space: MARGIN,
245247
buf: RingBuffer::new(),
246248
left_total: 0,
247249
right_total: 0,
@@ -395,7 +397,7 @@ impl Printer {
395397
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
396398
self.indent = match token.indent {
397399
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
398-
IndentStyle::Visual => (self.margin - self.space) as usize,
400+
IndentStyle::Visual => (MARGIN - self.space) as usize,
399401
};
400402
} else {
401403
self.print_stack.push(PrintFrame::Fits);
@@ -421,7 +423,7 @@ impl Printer {
421423
self.out.push('\n');
422424
let indent = self.indent as isize + token.offset;
423425
self.pending_indentation = indent;
424-
self.space = self.margin - indent;
426+
self.space = cmp::max(MARGIN - indent, MIN_SPACE);
425427
}
426428
}
427429

compiler/rustc_parse/src/parser/expr.rs

+25
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,19 @@ impl<'a> Parser<'a> {
17001700
s.len() > 1 && s.starts_with(first_chars) && s[1..].chars().all(|c| c.is_ascii_digit())
17011701
}
17021702

1703+
// Try to lowercase the prefix if it's a valid base prefix.
1704+
fn fix_base_capitalisation(s: &str) -> Option<String> {
1705+
if let Some(stripped) = s.strip_prefix("B") {
1706+
Some(format!("0b{stripped}"))
1707+
} else if let Some(stripped) = s.strip_prefix("O") {
1708+
Some(format!("0o{stripped}"))
1709+
} else if let Some(stripped) = s.strip_prefix("X") {
1710+
Some(format!("0x{stripped}"))
1711+
} else {
1712+
None
1713+
}
1714+
}
1715+
17031716
let token::Lit { kind, suffix, .. } = lit;
17041717
match err {
17051718
// `NotLiteral` is not an error by itself, so we don't report
@@ -1724,6 +1737,18 @@ impl<'a> Parser<'a> {
17241737
self.struct_span_err(span, &msg)
17251738
.help("valid widths are 8, 16, 32, 64 and 128")
17261739
.emit();
1740+
} else if let Some(fixed) = fix_base_capitalisation(suf) {
1741+
let msg = "invalid base prefix for number literal";
1742+
1743+
self.struct_span_err(span, &msg)
1744+
.note("base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase")
1745+
.span_suggestion(
1746+
span,
1747+
"try making the prefix lowercase",
1748+
fixed,
1749+
Applicability::MaybeIncorrect,
1750+
)
1751+
.emit();
17271752
} else {
17281753
let msg = format!("invalid suffix `{}` for number literal", suf);
17291754
self.struct_span_err(span, &msg)

compiler/rustc_serialize/src/opaque.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ impl serialize::Encoder for Encoder {
130130

131131
#[inline]
132132
fn emit_i8(&mut self, v: i8) -> EncodeResult {
133-
let as_u8: u8 = unsafe { std::mem::transmute(v) };
134-
self.emit_u8(as_u8)
133+
self.emit_u8(v as u8)
135134
}
136135

137136
#[inline]
@@ -629,9 +628,9 @@ impl<'a> serialize::Decoder for Decoder<'a> {
629628

630629
#[inline]
631630
fn read_i8(&mut self) -> i8 {
632-
let as_u8 = self.data[self.position];
631+
let value = self.data[self.position];
633632
self.position += 1;
634-
unsafe { ::std::mem::transmute(as_u8) }
633+
value as i8
635634
}
636635

637636
#[inline]

compiler/rustc_typeck/src/check/pat.rs

+34-7
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
1515
use rustc_span::hygiene::DesugaringKind;
1616
use rustc_span::lev_distance::find_best_match_for_name;
1717
use rustc_span::source_map::{Span, Spanned};
18-
use rustc_span::symbol::Ident;
18+
use rustc_span::symbol::{sym, Ident};
1919
use rustc_span::{BytePos, MultiSpan, DUMMY_SP};
2020
use rustc_trait_selection::autoderef::Autoderef;
2121
use rustc_trait_selection::traits::{ObligationCause, Pattern};
@@ -2033,12 +2033,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
20332033
{
20342034
if let (Some(span), true) = (ti.span, ti.origin_expr) {
20352035
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
2036-
err.span_suggestion(
2037-
span,
2038-
"consider slicing here",
2039-
format!("{}[..]", snippet),
2040-
Applicability::MachineApplicable,
2041-
);
2036+
let applicability = match self.resolve_vars_if_possible(ti.expected).kind() {
2037+
ty::Adt(adt_def, _)
2038+
if self.tcx.is_diagnostic_item(sym::Option, adt_def.did)
2039+
|| self.tcx.is_diagnostic_item(sym::Result, adt_def.did) =>
2040+
{
2041+
// Slicing won't work here, but `.as_deref()` might (issue #91328).
2042+
err.span_suggestion(
2043+
span,
2044+
"consider using `as_deref` here",
2045+
format!("{}.as_deref()", snippet),
2046+
Applicability::MaybeIncorrect,
2047+
);
2048+
None
2049+
}
2050+
// FIXME: instead of checking for Vec only, we could check whether the
2051+
// type implements `Deref<Target=X>`; see
2052+
// https://github.com/rust-lang/rust/pull/91343#discussion_r761466979
2053+
ty::Adt(adt_def, _)
2054+
if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did) =>
2055+
{
2056+
Some(Applicability::MachineApplicable)
2057+
}
2058+
_ => Some(Applicability::MaybeIncorrect),
2059+
};
2060+
2061+
if let Some(applicability) = applicability {
2062+
err.span_suggestion(
2063+
span,
2064+
"consider slicing here",
2065+
format!("{}[..]", snippet),
2066+
applicability,
2067+
);
2068+
}
20422069
}
20432070
}
20442071
}

library/std/src/io/error.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,29 @@ impl ErrorKind {
361361
}
362362
}
363363

364+
#[stable(feature = "io_errorkind_display", since = "1.60.0")]
365+
impl fmt::Display for ErrorKind {
366+
/// Shows a human-readable description of the `ErrorKind`.
367+
///
368+
/// This is similar to `impl Display for Error`, but doesn't require first converting to Error.
369+
///
370+
/// # Examples
371+
/// ```
372+
/// use std::io::ErrorKind;
373+
/// assert_eq!("entity not found", ErrorKind::NotFound.to_string());
374+
/// ```
375+
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
376+
fmt.write_str(self.as_str())
377+
}
378+
}
379+
364380
/// Intended for use for errors not exposed to the user, where allocating onto
365381
/// the heap (for normal construction via Error::new) is too costly.
366382
#[stable(feature = "io_error_from_errorkind", since = "1.14.0")]
367383
impl From<ErrorKind> for Error {
368384
/// Converts an [`ErrorKind`] into an [`Error`].
369385
///
370-
/// This conversion allocates a new error with a simple representation of error kind.
386+
/// This conversion creates a new error with a simple representation of error kind.
371387
///
372388
/// # Examples
373389
///

library/std/src/sys/itron/thread.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ const LIFECYCLE_DETACHED_OR_JOINED: usize = usize::MAX;
7777
const LIFECYCLE_EXITED_OR_FINISHED_OR_JOIN_FINALIZE: usize = usize::MAX;
7878
// there's no single value for `JOINING`
7979

80-
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * crate::mem::size_of::<usize>();
80+
// 64KiB for 32-bit ISAs, 128KiB for 64-bit ISAs.
81+
pub const DEFAULT_MIN_STACK_SIZE: usize = 0x4000 * crate::mem::size_of::<usize>();
8182

8283
impl Thread {
8384
/// # Safety

src/bootstrap/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ impl Build {
851851
return;
852852
}
853853
self.verbose(&format!("running: {:?}", cmd));
854-
run(cmd)
854+
run(cmd, self.is_verbose())
855855
}
856856

857857
/// Runs a command, printing out nice contextual information if it fails.
@@ -871,7 +871,7 @@ impl Build {
871871
return true;
872872
}
873873
self.verbose(&format!("running: {:?}", cmd));
874-
try_run(cmd)
874+
try_run(cmd, self.is_verbose())
875875
}
876876

877877
/// Runs a command, printing out nice contextual information if it fails.

src/build_helper/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,18 @@ pub fn restore_library_path() {
5555
}
5656
}
5757

58-
pub fn run(cmd: &mut Command) {
59-
if !try_run(cmd) {
58+
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
59+
if !try_run(cmd, print_cmd_on_fail) {
6060
std::process::exit(1);
6161
}
6262
}
6363

64-
pub fn try_run(cmd: &mut Command) -> bool {
64+
pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
6565
let status = match cmd.status() {
6666
Ok(status) => status,
6767
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
6868
};
69-
if !status.success() {
69+
if !status.success() && print_cmd_on_fail {
7070
println!(
7171
"\n\ncommand did not execute successfully: {:?}\n\
7272
expected success, got: {}\n\n",

src/doc/embedded-book

src/test/pretty/issue-4264.pp

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@
3535
for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1
3636
as
3737
fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
38-
as &str)] as [&str; 1]) as
39-
&[&str; 1]),
38+
as &str)] as [&str; 1]) as &[&str; 1]),
4039
(&([] as [ArgumentV1; 0]) as &[ArgumentV1; 0])) as
4140
Arguments)) as String);
4241
(res as String)

src/test/ui/match/issue-82392.stdout

+2-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ pub fn main() ({
1111
({ } as
1212
()) else if (let Some(a) =
1313
((Some as
14-
fn(i32) -> Option<i32> {Option::<i32>::Some})((3
15-
as i32)) as Option<i32>) as bool) ({ } as ())
16-
as ())
14+
fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as
15+
Option<i32>) as bool) ({ } as ()) as ())
1716
} as ())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// run-rustfix
2+
// Checks that integers with an uppercase base prefix (0B, 0X, 0O) have a nice error
3+
#![allow(unused_variables)]
4+
5+
fn main() {
6+
let a = 0xABCDEF;
7+
//~^ ERROR invalid base prefix for number literal
8+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
9+
//~| HELP try making the prefix lowercase
10+
//~| SUGGESTION 0xABCDEF
11+
12+
let b = 0o755;
13+
//~^ ERROR invalid base prefix for number literal
14+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
15+
//~| HELP try making the prefix lowercase
16+
//~| SUGGESTION 0o755
17+
18+
let c = 0b10101010;
19+
//~^ ERROR invalid base prefix for number literal
20+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
21+
//~| HELP try making the prefix lowercase
22+
//~| SUGGESTION 0b10101010
23+
24+
let d = 0xABC_DEF;
25+
//~^ ERROR invalid base prefix for number literal
26+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
27+
//~| HELP try making the prefix lowercase
28+
//~| SUGGESTION 0xABC_DEF
29+
30+
let e = 0o7_55;
31+
//~^ ERROR invalid base prefix for number literal
32+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
33+
//~| HELP try making the prefix lowercase
34+
//~| SUGGESTION 0o7_55
35+
36+
let f = 0b1010_1010;
37+
//~^ ERROR invalid base prefix for number literal
38+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
39+
//~| HELP try making the prefix lowercase
40+
//~| SUGGESTION 0b1010_1010
41+
42+
let g = 0xABC_DEF_u64;
43+
//~^ ERROR invalid base prefix for number literal
44+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
45+
//~| HELP try making the prefix lowercase
46+
//~| SUGGESTION 0xABC_DEF_u64
47+
48+
let h = 0o7_55_u32;
49+
//~^ ERROR invalid base prefix for number literal
50+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
51+
//~| HELP try making the prefix lowercase
52+
//~| SUGGESTION 0o7_55_u32
53+
54+
let i = 0b1010_1010_u8;
55+
//~^ ERROR invalid base prefix for number literal
56+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
57+
//~| HELP try making the prefix lowercase
58+
//~| SUGGESTION 0b1010_1010_u8
59+
//
60+
let j = 0xABCDEFu64;
61+
//~^ ERROR invalid base prefix for number literal
62+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
63+
//~| HELP try making the prefix lowercase
64+
//~| SUGGESTION 0xABCDEFu64
65+
66+
let k = 0o755u32;
67+
//~^ ERROR invalid base prefix for number literal
68+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
69+
//~| HELP try making the prefix lowercase
70+
//~| SUGGESTION 0o755u32
71+
72+
let l = 0b10101010u8;
73+
//~^ ERROR invalid base prefix for number literal
74+
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
75+
//~| HELP try making the prefix lowercase
76+
//~| SUGGESTION 0b10101010u8
77+
}

0 commit comments

Comments
 (0)