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 8 pull requests #80939

Merged
merged 22 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8ca8b77
Add test for trimming with tabs (#78438)
jryans Dec 5, 2020
3537bd8
Replace tabs earlier in diagnostics
jryans Dec 6, 2020
826bc36
Implement MaybeUninit::array_assume_init
joboet Jan 1, 2021
0ff1e6c
Add test for MaybeUninit::array_assume_init
joboet Jan 1, 2021
72a3dee
Format code
joboet Jan 1, 2021
39e1331
Add another test case for #79808
JohnTitor Jan 11, 2021
dec8c03
Add tracking issue for array_assume_init
joboet Jan 11, 2021
0be9d39
core/slice: remove doc comment about scoped borrow
epilys Jan 11, 2021
5d65b7e
Simplify array_assume_init
joboet Jan 11, 2021
2055e4c
Move some tests to more reasonable directories
c410-f3r Jan 11, 2021
b6dc03b
fix typo in trait method mutability mismatch help
euclio Jan 12, 2021
985071b
Fix implementation
joboet Jan 12, 2021
6bd661e
Replace a simple `if let` with the `matches` macro
LingMan Jan 11, 2021
8c43160
driver: Use `atty` instead of rolling our own
camelid Jan 11, 2021
86b900a
Rollup merge of #79757 - jryans:long-line-tab-handling-early-expand, …
JohnTitor Jan 12, 2021
babfdaf
Rollup merge of #80600 - CoffeeBlend:maybe_uninit_array_assume_init, …
JohnTitor Jan 12, 2021
7c79e5b
Rollup merge of #80880 - c410-f3r:tests-tests-tests, r=petrochenkov
JohnTitor Jan 12, 2021
d682a68
Rollup merge of #80897 - camelid:atty, r=jyn514
JohnTitor Jan 12, 2021
a9e3125
Rollup merge of #80898 - JohnTitor:vecdeque-another-case, r=lcnr
JohnTitor Jan 12, 2021
961a438
Rollup merge of #80917 - epilys:patch-1, r=jyn514
JohnTitor Jan 12, 2021
8c342da
Rollup merge of #80927 - LingMan:matches, r=estebank
JohnTitor Jan 12, 2021
139daf5
Rollup merge of #80930 - euclio:trait-method-mutability-help, r=estebank
JohnTitor Jan 12, 2021
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
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3652,6 +3652,7 @@ dependencies = [
name = "rustc_driver"
version = "0.0.0"
dependencies = [
"atty",
"libc",
"rustc_ast",
"rustc_ast_pretty",
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ crate-type = ["dylib"]

[dependencies]
libc = "0.2"
atty = "0.2"
tracing = { version = "0.1.18" }
tracing-subscriber = { version = "0.2.13", default-features = false, features = ["fmt", "env-filter", "smallvec", "parking_lot", "ansi"] }
tracing-tree = "0.1.6"
Expand Down
35 changes: 2 additions & 33 deletions compiler/rustc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,43 +546,12 @@ impl Compilation {
#[derive(Copy, Clone)]
pub struct RustcDefaultCalls;

// FIXME remove these and use winapi 0.3 instead
// Duplicates: bootstrap/compile.rs, librustc_errors/emitter.rs
#[cfg(unix)]
fn stdout_isatty() -> bool {
unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 }
}

#[cfg(windows)]
fn stdout_isatty() -> bool {
use winapi::um::consoleapi::GetConsoleMode;
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::STD_OUTPUT_HANDLE;

unsafe {
let handle = GetStdHandle(STD_OUTPUT_HANDLE);
let mut out = 0;
GetConsoleMode(handle, &mut out) != 0
}
atty::is(atty::Stream::Stdout)
}

// FIXME remove these and use winapi 0.3 instead
#[cfg(unix)]
fn stderr_isatty() -> bool {
unsafe { libc::isatty(libc::STDERR_FILENO) != 0 }
}

#[cfg(windows)]
fn stderr_isatty() -> bool {
use winapi::um::consoleapi::GetConsoleMode;
use winapi::um::processenv::GetStdHandle;
use winapi::um::winbase::STD_ERROR_HANDLE;

unsafe {
let handle = GetStdHandle(STD_ERROR_HANDLE);
let mut out = 0;
GetConsoleMode(handle, &mut out) != 0
}
atty::is(atty::Stream::Stderr)
}

fn handle_explain(registry: Registry, code: &str, output: ErrorOutputType) {
Expand Down
25 changes: 20 additions & 5 deletions compiler/rustc_errors/src/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ impl EmitterWriter {
code_offset: usize,
margin: Margin,
) {
// Tabs are assumed to have been replaced by spaces in calling code.
assert!(!source_string.contains('\t'));
let line_len = source_string.len();
// Create the source line we will highlight.
let left = margin.left(line_len);
Expand Down Expand Up @@ -707,7 +709,7 @@ impl EmitterWriter {
}

let source_string = match file.get_line(line.line_index - 1) {
Some(s) => s,
Some(s) => replace_tabs(&*s),
None => return Vec::new(),
};

Expand Down Expand Up @@ -1376,8 +1378,17 @@ impl EmitterWriter {
let file = annotated_file.file.clone();
let line = &annotated_file.lines[line_idx];
if let Some(source_string) = file.get_line(line.line_index - 1) {
let leading_whitespace =
source_string.chars().take_while(|c| c.is_whitespace()).count();
let leading_whitespace = source_string
.chars()
.take_while(|c| c.is_whitespace())
.map(|c| {
match c {
// Tabs are displayed as 4 spaces
'\t' => 4,
_ => 1,
}
})
.sum();
if source_string.chars().any(|c| !c.is_whitespace()) {
whitespace_margin = min(whitespace_margin, leading_whitespace);
}
Expand Down Expand Up @@ -1502,7 +1513,7 @@ impl EmitterWriter {

self.draw_line(
&mut buffer,
&unannotated_line,
&replace_tabs(&unannotated_line),
annotated_file.lines[line_idx + 1].line_index - 1,
last_buffer_line_num,
width_offset,
Expand Down Expand Up @@ -1598,7 +1609,7 @@ impl EmitterWriter {
);
// print the suggestion
draw_col_separator(&mut buffer, row_num, max_line_num_len + 1);
buffer.append(row_num, line, Style::NoStyle);
buffer.append(row_num, &replace_tabs(line), Style::NoStyle);
row_num += 1;
}

Expand Down Expand Up @@ -1930,6 +1941,10 @@ impl FileWithAnnotatedLines {
}
}

fn replace_tabs(str: &str) -> String {
str.replace('\t', " ")
}

fn draw_col_separator(buffer: &mut StyledBuffer, line: usize, col: usize) {
buffer.puts(line, col, "| ", Style::LineNumber);
}
Expand Down
27 changes: 3 additions & 24 deletions compiler/rustc_errors/src/styled_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,13 @@ impl StyledBuffer {
StyledBuffer { text: vec![], styles: vec![] }
}

fn replace_tabs(&mut self) {
for (line_pos, line) in self.text.iter_mut().enumerate() {
let mut tab_pos = vec![];
for (pos, c) in line.iter().enumerate() {
if *c == '\t' {
tab_pos.push(pos);
}
}
// start with the tabs at the end of the line to replace them with 4 space chars
for pos in tab_pos.iter().rev() {
assert_eq!(line.remove(*pos), '\t');
// fix the position of the style to match up after replacing the tabs
let s = self.styles[line_pos].remove(*pos);
for _ in 0..4 {
line.insert(*pos, ' ');
self.styles[line_pos].insert(*pos, s);
}
}
}
}
pub fn render(&self) -> Vec<Vec<StyledString>> {
// Tabs are assumed to have been replaced by spaces in calling code.
assert!(self.text.iter().all(|r| !r.contains(&'\t')));

pub fn render(&mut self) -> Vec<Vec<StyledString>> {
let mut output: Vec<Vec<StyledString>> = vec![];
let mut styled_vec: Vec<StyledString> = vec![];

// before we render, replace tabs with spaces
self.replace_tabs();

for (row, row_style) in self.text.iter().zip(&self.styles) {
let mut current_style = Style::NoStyle;
let mut current_text = String::new();
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1947,8 +1947,7 @@ impl<'a: 'ast, 'b, 'ast> LateResolutionVisitor<'a, 'b, 'ast> {
_ => report_errors(self, None),
};

if let PathSource::TraitItem(..) = source {
} else {
if !matches!(source, PathSource::TraitItem(..)) {
// Avoid recording definition of `A::B` in `<T as A>::B::C`.
self.r.record_partial_res(id, partial_res);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_typeck/src/check/compare_method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ fn compare_predicate_entailment<'tcx>(
{
diag.span_suggestion(
impl_err_span,
"consider change the type to match the mutability in trait",
"consider changing the mutability to match the trait",
trait_err_str,
Applicability::MachineApplicable,
);
Expand Down
15 changes: 15 additions & 0 deletions library/alloc/src/collections/vec_deque/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,21 @@ fn make_contiguous_head_to_end() {
assert_eq!((&['A', 'B', 'C'] as &[_], &[] as &[_]), dq.as_slices());
}

#[test]
fn make_contiguous_head_to_end_2() {
// Another test case for #79808, taken from #80293.

let mut dq = VecDeque::from_iter(0..6);
dq.pop_front();
dq.pop_front();
dq.push_back(6);
dq.push_back(7);
dq.push_back(8);
dq.make_contiguous();
let collected: Vec<_> = dq.iter().copied().collect();
assert_eq!(dq.as_slices(), (&collected[..], &[] as &[_]));
}

#[test]
fn test_remove() {
// This test checks that every single combination of tail position, length, and
Expand Down
40 changes: 40 additions & 0 deletions library/core/src/mem/maybe_uninit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,46 @@ impl<T> MaybeUninit<T> {
}
}

/// Extracts the values from an array of `MaybeUninit` containers.
///
/// # Safety
///
/// It is up to the caller to guarantee that all elements of the array are
/// in an initialized state.
///
/// # Examples
///
/// ```
/// #![feature(maybe_uninit_uninit_array)]
/// #![feature(maybe_uninit_array_assume_init)]
/// use std::mem::MaybeUninit;
///
/// let mut array: [MaybeUninit<i32>; 3] = MaybeUninit::uninit_array();
/// array[0] = MaybeUninit::new(0);
/// array[1] = MaybeUninit::new(1);
/// array[2] = MaybeUninit::new(2);
///
/// // SAFETY: Now safe as we initialised all elements
/// let array = unsafe {
/// MaybeUninit::array_assume_init(array)
/// };
///
/// assert_eq!(array, [0, 1, 2]);
/// ```
#[unstable(feature = "maybe_uninit_array_assume_init", issue = "80908")]
#[inline(always)]
pub unsafe fn array_assume_init<const N: usize>(array: [Self; N]) -> [T; N] {
// SAFETY:
// * The caller guarantees that all elements of the array are initialized
// * `MaybeUninit<T>` and T are guaranteed to have the same layout
// * MaybeUnint does not drop, so there are no double-frees
// And thus the conversion is safe
unsafe {
intrinsics::assert_inhabited::<T>();
(&array as *const _ as *const [T; N]).read()
}
}

/// Assuming all the elements are initialized, get a slice to them.
///
/// # Safety
Expand Down
13 changes: 5 additions & 8 deletions library/core/src/slice/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,14 +1357,11 @@ impl<T> [T] {
///
/// ```
/// let mut v = [1, 0, 3, 0, 5, 6];
/// // scoped to restrict the lifetime of the borrows
/// {
/// let (left, right) = v.split_at_mut(2);
/// assert_eq!(left, [1, 0]);
/// assert_eq!(right, [3, 0, 5, 6]);
/// left[1] = 2;
/// right[1] = 4;
/// }
/// let (left, right) = v.split_at_mut(2);
/// assert_eq!(left, [1, 0]);
/// assert_eq!(right, [3, 0, 5, 6]);
/// left[1] = 2;
/// right[1] = 4;
/// assert_eq!(v, [1, 2, 3, 4, 5, 6]);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
Expand Down
2 changes: 2 additions & 0 deletions library/core/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#![feature(raw)]
#![feature(sort_internals)]
#![feature(slice_partition_at_index)]
#![feature(maybe_uninit_uninit_array)]
#![feature(maybe_uninit_array_assume_init)]
#![feature(maybe_uninit_extra)]
#![feature(maybe_uninit_write_slice)]
#![feature(min_specialization)]
Expand Down
14 changes: 14 additions & 0 deletions library/core/tests/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,20 @@ fn assume_init_good() {
assert!(TRUE);
}

#[test]
fn uninit_array_assume_init() {
let mut array: [MaybeUninit<i16>; 5] = MaybeUninit::uninit_array();
array[0].write(3);
array[1].write(1);
array[2].write(4);
array[3].write(1);
array[4].write(5);

let array = unsafe { MaybeUninit::array_assume_init(array) };

assert_eq!(array, [3, 1, 4, 1, 5]);
}

#[test]
fn uninit_write_slice() {
let mut dst = [MaybeUninit::new(255); 64];
Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion src/test/ui/issues/auxiliary/issue-10031-aux.rs

This file was deleted.

9 changes: 0 additions & 9 deletions src/test/ui/issues/issue-10031.rs

This file was deleted.

9 changes: 4 additions & 5 deletions src/test/ui/issues/issue-13033.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ LL | fn bar(&mut self, other: &mut dyn Foo);
| ------------ type in trait
...
LL | fn bar(&mut self, other: &dyn Foo) {}
| ^^^^^^^^ types differ in mutability
| ^^^^^^^^
| |
| types differ in mutability
| help: consider changing the mutability to match the trait: `&mut dyn Foo`
|
= note: expected fn pointer `fn(&mut Baz, &mut dyn Foo)`
found fn pointer `fn(&mut Baz, &dyn Foo)`
help: consider change the type to match the mutability in trait
|
LL | fn bar(&mut self, other: &mut dyn Foo) {}
| ^^^^^^^^^^^^

error: aborting due to previous error

Expand Down
9 changes: 4 additions & 5 deletions src/test/ui/mismatched_types/E0053.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ LL | fn bar(&self);
| ----- type in trait
...
LL | fn bar(&mut self) { }
| ^^^^^^^^^ types differ in mutability
| ^^^^^^^^^
| |
| types differ in mutability
| help: consider changing the mutability to match the trait: `&self`
|
= note: expected fn pointer `fn(&Bar)`
found fn pointer `fn(&mut Bar)`
help: consider change the type to match the mutability in trait
|
LL | fn bar(&self) { }
| ^^^^^

error: aborting due to 2 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@ LL | fn bar(&mut self, bar: &mut Bar);
| -------- type in trait
...
LL | fn bar(&mut self, bar: &Bar) { }
| ^^^^ types differ in mutability
| ^^^^
| |
| types differ in mutability
| help: consider changing the mutability to match the trait: `&mut Bar`
|
= note: expected fn pointer `fn(&mut Bar, &mut Bar)`
found fn pointer `fn(&mut Bar, &Bar)`
help: consider change the type to match the mutability in trait
|
LL | fn bar(&mut self, bar: &mut Bar) { }
| ^^^^^^^^

error: aborting due to 2 previous errors

Expand Down
File renamed without changes.
13 changes: 13 additions & 0 deletions src/test/ui/terminal-width/tabs-trimming.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Test for #78438: ensure underline alignment with many tabs on the left, long line on the right

// ignore-tidy-linelength
// ignore-tidy-tab

fn main() {
let money = 42i32;
match money {
v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
//~^ ERROR variable `v` is not bound in all patterns
v => println!("Enough money {}", v),
}
}
Loading