Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #93534

Merged
merged 23 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f8ee57b
`impl Display for io::ErrorKind`
jyn514 Jan 19, 2022
7f24778
Suggest making base prefix lowercase if parsing fails
5225225 Jan 17, 2022
9bf6a5d
Hide failed command unless in verbose mode
Mark-Simulacrum Jan 30, 2022
1a77d62
kmc-solid: Increase the default stack size
kawadakk Jan 31, 2022
0b8f372
Remove two unnecessary transmutes from opaque Encoder and Decoder
bjorn3 Jan 29, 2022
ec3b711
Write UI tests, tweak message
5225225 Jan 27, 2022
c15ef58
Fix suggestion to slice if scrutinee is a `Result` or `Option`
FabianWolff Nov 29, 2021
0363f11
Add match on `Vec<_>` to `ui/typeck/issue-91328.rs` test
FabianWolff Jan 15, 2022
67259e7
Extract constant MARGIN out of Printer struct
dtolnay Jan 31, 2022
6db97b3
Allow any line to have at least 60 chars
dtolnay Jan 31, 2022
7739fca
Bless all pretty printer tests and ui tests
dtolnay Jan 21, 2022
95344c0
Add FIXME comment
FabianWolff Jan 31, 2022
5159c01
Rollup merge of #91343 - FabianWolff:issue-91328-as-deref, r=jackh726
ehuss Feb 1, 2022
d7c0b4f
Rollup merge of #93019 - 5225225:uppercase-suffix, r=wesleywiser
ehuss Feb 1, 2022
8604161
Rollup merge of #93090 - jyn514:errorkind-asstr, r=dtolnay
ehuss Feb 1, 2022
3aa2e45
Rollup merge of #93456 - bjorn3:remove_unnecessary_unsafe, r=michaelw…
ehuss Feb 1, 2022
445fbff
Rollup merge of #93492 - Mark-Simulacrum:shorter-failure-output, r=ehuss
ehuss Feb 1, 2022
8a70ea2
Rollup merge of #93504 - solid-rs:fix-kmc-solid-stack-size, r=nagisa
ehuss Feb 1, 2022
2e39a3f
Rollup merge of #93513 - dtolnay:linewidth, r=nagisa
ehuss Feb 1, 2022
641bde0
Update books
ehuss Feb 1, 2022
06c7d32
Rollup merge of #93532 - ehuss:update-books, r=ehuss
ehuss Feb 1, 2022
91aee65
Update cargo
ehuss Feb 1, 2022
81900f4
Rollup merge of #93533 - ehuss:update-cargo, r=ehuss
ehuss Feb 1, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ dependencies = [
"cargo-test-macro",
"cargo-test-support",
"cargo-util",
"clap 3.0.10",
"clap 3.0.13",
"crates-io",
"crossbeam-utils",
"curl",
Expand Down Expand Up @@ -627,9 +627,9 @@ dependencies = [

[[package]]
name = "clap"
version = "3.0.10"
version = "3.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a30c3bf9ff12dfe5dae53f0a96e0febcd18420d1c0e7fad77796d9d5c4b5375"
checksum = "08799f92c961c7a1cf0cc398a9073da99e21ce388b46372c37f3191f2f3eed3e"
dependencies = [
"atty",
"bitflags",
Expand Down Expand Up @@ -5233,9 +5233,9 @@ dependencies = [

[[package]]
name = "toml_edit"
version = "0.13.0"
version = "0.13.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b80ac5e1b91e3378c63dab121962472b5ca20cf9ab1975e3d588548717807a8"
checksum = "744e9ed5b352340aa47ce033716991b5589e23781acb97cad37d4ea70560f55b"
dependencies = [
"combine",
"indexmap",
Expand Down
16 changes: 9 additions & 7 deletions compiler/rustc_ast_pretty/src/pp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ mod ring;

use ring::RingBuffer;
use std::borrow::Cow;
use std::cmp;
use std::collections::VecDeque;
use std::iter;

Expand Down Expand Up @@ -199,10 +200,13 @@ enum PrintFrame {

const SIZE_INFINITY: isize = 0xffff;

/// Target line width.
const MARGIN: isize = 78;
/// Every line is allowed at least this much space, even if highly indented.
const MIN_SPACE: isize = 60;

pub struct Printer {
out: String,
/// Width of lines we're constrained to
margin: isize,
/// Number of spaces left on line
space: isize,
/// Ring-buffer of tokens and calculated sizes
Expand Down Expand Up @@ -237,11 +241,9 @@ struct BufEntry {

impl Printer {
pub fn new() -> Self {
let linewidth = 78;
Printer {
out: String::new(),
margin: linewidth as isize,
space: linewidth as isize,
space: MARGIN,
buf: RingBuffer::new(),
left_total: 0,
right_total: 0,
Expand Down Expand Up @@ -395,7 +397,7 @@ impl Printer {
self.print_stack.push(PrintFrame::Broken { indent: self.indent, breaks: token.breaks });
self.indent = match token.indent {
IndentStyle::Block { offset } => (self.indent as isize + offset) as usize,
IndentStyle::Visual => (self.margin - self.space) as usize,
IndentStyle::Visual => (MARGIN - self.space) as usize,
};
} else {
self.print_stack.push(PrintFrame::Fits);
Expand All @@ -421,7 +423,7 @@ impl Printer {
self.out.push('\n');
let indent = self.indent as isize + token.offset;
self.pending_indentation = indent;
self.space = self.margin - indent;
self.space = cmp::max(MARGIN - indent, MIN_SPACE);
}
}

Expand Down
25 changes: 25 additions & 0 deletions compiler/rustc_parse/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,19 @@ impl<'a> Parser<'a> {
s.len() > 1 && s.starts_with(first_chars) && s[1..].chars().all(|c| c.is_ascii_digit())
}

// Try to lowercase the prefix if it's a valid base prefix.
fn fix_base_capitalisation(s: &str) -> Option<String> {
if let Some(stripped) = s.strip_prefix("B") {
Some(format!("0b{stripped}"))
} else if let Some(stripped) = s.strip_prefix("O") {
Some(format!("0o{stripped}"))
} else if let Some(stripped) = s.strip_prefix("X") {
Some(format!("0x{stripped}"))
} else {
None
}
}

let token::Lit { kind, suffix, .. } = lit;
match err {
// `NotLiteral` is not an error by itself, so we don't report
Expand All @@ -1724,6 +1737,18 @@ impl<'a> Parser<'a> {
self.struct_span_err(span, &msg)
.help("valid widths are 8, 16, 32, 64 and 128")
.emit();
} else if let Some(fixed) = fix_base_capitalisation(suf) {
let msg = "invalid base prefix for number literal";

self.struct_span_err(span, &msg)
.note("base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase")
.span_suggestion(
span,
"try making the prefix lowercase",
fixed,
Applicability::MaybeIncorrect,
)
.emit();
} else {
let msg = format!("invalid suffix `{}` for number literal", suf);
self.struct_span_err(span, &msg)
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_serialize/src/opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ impl serialize::Encoder for Encoder {

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

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

#[inline]
fn read_i8(&mut self) -> i8 {
let as_u8 = self.data[self.position];
let value = self.data[self.position];
self.position += 1;
unsafe { ::std::mem::transmute(as_u8) }
value as i8
}

#[inline]
Expand Down
41 changes: 34 additions & 7 deletions compiler/rustc_typeck/src/check/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::hygiene::DesugaringKind;
use rustc_span::lev_distance::find_best_match_for_name;
use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::Ident;
use rustc_span::symbol::{sym, Ident};
use rustc_span::{BytePos, MultiSpan, DUMMY_SP};
use rustc_trait_selection::autoderef::Autoderef;
use rustc_trait_selection::traits::{ObligationCause, Pattern};
Expand Down Expand Up @@ -2033,12 +2033,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
{
if let (Some(span), true) = (ti.span, ti.origin_expr) {
if let Ok(snippet) = self.tcx.sess.source_map().span_to_snippet(span) {
err.span_suggestion(
span,
"consider slicing here",
format!("{}[..]", snippet),
Applicability::MachineApplicable,
);
let applicability = match self.resolve_vars_if_possible(ti.expected).kind() {
ty::Adt(adt_def, _)
if self.tcx.is_diagnostic_item(sym::Option, adt_def.did)
|| self.tcx.is_diagnostic_item(sym::Result, adt_def.did) =>
{
// Slicing won't work here, but `.as_deref()` might (issue #91328).
err.span_suggestion(
span,
"consider using `as_deref` here",
format!("{}.as_deref()", snippet),
Applicability::MaybeIncorrect,
);
None
}
// FIXME: instead of checking for Vec only, we could check whether the
// type implements `Deref<Target=X>`; see
// https://github.com/rust-lang/rust/pull/91343#discussion_r761466979
ty::Adt(adt_def, _)
if self.tcx.is_diagnostic_item(sym::Vec, adt_def.did) =>
{
Some(Applicability::MachineApplicable)
}
_ => Some(Applicability::MaybeIncorrect),
};

if let Some(applicability) = applicability {
err.span_suggestion(
span,
"consider slicing here",
format!("{}[..]", snippet),
applicability,
);
}
}
}
}
Expand Down
18 changes: 17 additions & 1 deletion library/std/src/io/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,13 +361,29 @@ impl ErrorKind {
}
}

#[stable(feature = "io_errorkind_display", since = "1.60.0")]
impl fmt::Display for ErrorKind {
/// Shows a human-readable description of the `ErrorKind`.
///
/// This is similar to `impl Display for Error`, but doesn't require first converting to Error.
///
/// # Examples
/// ```
/// use std::io::ErrorKind;
/// assert_eq!("entity not found", ErrorKind::NotFound.to_string());
/// ```
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.write_str(self.as_str())
}
}

/// Intended for use for errors not exposed to the user, where allocating onto
/// the heap (for normal construction via Error::new) is too costly.
#[stable(feature = "io_error_from_errorkind", since = "1.14.0")]
impl From<ErrorKind> for Error {
/// Converts an [`ErrorKind`] into an [`Error`].
///
/// This conversion allocates a new error with a simple representation of error kind.
/// This conversion creates a new error with a simple representation of error kind.
///
/// # Examples
///
Expand Down
3 changes: 2 additions & 1 deletion library/std/src/sys/itron/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ const LIFECYCLE_DETACHED_OR_JOINED: usize = usize::MAX;
const LIFECYCLE_EXITED_OR_FINISHED_OR_JOIN_FINALIZE: usize = usize::MAX;
// there's no single value for `JOINING`

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

impl Thread {
/// # Safety
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,7 +851,7 @@ impl Build {
return;
}
self.verbose(&format!("running: {:?}", cmd));
run(cmd)
run(cmd, self.is_verbose())
}

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

/// Runs a command, printing out nice contextual information if it fails.
Expand Down
8 changes: 4 additions & 4 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,18 @@ pub fn restore_library_path() {
}
}

pub fn run(cmd: &mut Command) {
if !try_run(cmd) {
pub fn run(cmd: &mut Command, print_cmd_on_fail: bool) {
if !try_run(cmd, print_cmd_on_fail) {
std::process::exit(1);
}
}

pub fn try_run(cmd: &mut Command) -> bool {
pub fn try_run(cmd: &mut Command, print_cmd_on_fail: bool) -> bool {
let status = match cmd.status() {
Ok(status) => status,
Err(e) => fail(&format!("failed to execute command: {:?}\nerror: {}", cmd, e)),
};
if !status.success() {
if !status.success() && print_cmd_on_fail {
println!(
"\n\ncommand did not execute successfully: {:?}\n\
expected success, got: {}\n\n",
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
Submodule book updated 30 files
+2 −2 .github/workflows/main.yml
+27 −2 listings/ch02-guessing-game-tutorial/listing-02-04/output.txt
+2 −0 listings/ch03-common-programming-concepts/no-listing-05-mut-cant-change-types/output.txt
+9 −10 listings/ch09-error-handling/listing-09-10/output.txt
+0 −6 listings/ch09-error-handling/no-listing-03-closures/Cargo.lock
+0 −6 listings/ch09-error-handling/no-listing-03-closures/Cargo.toml
+0 −14 listings/ch09-error-handling/no-listing-03-closures/src/main.rs
+0 −6 listings/ch17-oop/no-listing-01-trait-object-of-clone/Cargo.lock
+0 −6 listings/ch17-oop/no-listing-01-trait-object-of-clone/Cargo.toml
+0 −13 listings/ch17-oop/no-listing-01-trait-object-of-clone/output.txt
+0 −3 listings/ch17-oop/no-listing-01-trait-object-of-clone/src/lib.rs
+0 −5 listings/ch19-advanced-features/listing-19-20/output.txt
+5 −4 listings/ch20-web-server/no-listing-04-update-worker-definition/output.txt
+211 −184 nostarch/chapter09.md
+2,001 −0 nostarch/chapter15.md
+1,204 −0 nostarch/chapter16.md
+1,208 −0 nostarch/chapter17.md
+1 −1 rust-toolchain
+10 −10 src/ch09-00-error-handling.md
+28 −28 src/ch09-01-unrecoverable-errors-with-panic.md
+133 −119 src/ch09-02-recoverable-errors-with-result.md
+18 −20 src/ch09-03-to-panic-or-not-to-panic.md
+11 −5 src/ch15-02-deref.md
+2 −3 src/ch15-04-rc.md
+12 −42 src/ch16-01-threads.md
+5 −5 src/ch16-03-shared-state.md
+0 −59 src/ch17-02-trait-objects.md
+21 −19 src/ch17-03-oo-design-patterns.md
+2 −2 src/ch20-02-multithreaded.md
+4 −1 src/title-page.md
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/rustc-dev-guide
3 changes: 1 addition & 2 deletions src/test/pretty/issue-4264.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@
for<'r> fn(Arguments<'r>) -> String {format})(((::core::fmt::Arguments::new_v1
as
fn(&[&'static str], &[ArgumentV1]) -> Arguments {Arguments::new_v1})((&([("test"
as &str)] as [&str; 1]) as
&[&str; 1]),
as &str)] as [&str; 1]) as &[&str; 1]),
(&([] as [ArgumentV1; 0]) as &[ArgumentV1; 0])) as
Arguments)) as String);
(res as String)
Expand Down
5 changes: 2 additions & 3 deletions src/test/ui/match/issue-82392.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ pub fn main() ({
({ } as
()) else if (let Some(a) =
((Some as
fn(i32) -> Option<i32> {Option::<i32>::Some})((3
as i32)) as Option<i32>) as bool) ({ } as ())
as ())
fn(i32) -> Option<i32> {Option::<i32>::Some})((3 as i32)) as
Option<i32>) as bool) ({ } as ()) as ())
} as ())
77 changes: 77 additions & 0 deletions src/test/ui/numeric/uppercase-base-prefix.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// run-rustfix
// Checks that integers with an uppercase base prefix (0B, 0X, 0O) have a nice error
#![allow(unused_variables)]

fn main() {
let a = 0xABCDEF;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0xABCDEF

let b = 0o755;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0o755

let c = 0b10101010;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0b10101010

let d = 0xABC_DEF;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0xABC_DEF

let e = 0o7_55;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0o7_55

let f = 0b1010_1010;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0b1010_1010

let g = 0xABC_DEF_u64;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0xABC_DEF_u64

let h = 0o7_55_u32;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0o7_55_u32

let i = 0b1010_1010_u8;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0b1010_1010_u8
//
let j = 0xABCDEFu64;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0xABCDEFu64

let k = 0o755u32;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0o755u32

let l = 0b10101010u8;
//~^ ERROR invalid base prefix for number literal
//~| NOTE base prefixes (`0xff`, `0b1010`, `0o755`) are lowercase
//~| HELP try making the prefix lowercase
//~| SUGGESTION 0b10101010u8
}
Loading