mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-17 01:13:11 +00:00
Auto merge of #80939 - JohnTitor:rollup-pymns4q, r=JohnTitor
Rollup of 8 pull requests Successful merges: - #79757 (Replace tabs earlier in diagnostics) - #80600 (Add `MaybeUninit` method `array_assume_init`) - #80880 (Move some tests to more reasonable directories) - #80897 (driver: Use `atty` instead of rolling our own) - #80898 (Add another test case for #79808) - #80917 (core/slice: remove doc comment about scoped borrow) - #80927 (Replace a simple `if let` with the `matches` macro) - #80930 (fix typo in trait method mutability mismatch help) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
b6b461652a
@ -3652,6 +3652,7 @@ dependencies = [
|
||||
name = "rustc_driver"
|
||||
version = "0.0.0"
|
||||
dependencies = [
|
||||
"atty",
|
||||
"libc",
|
||||
"rustc_ast",
|
||||
"rustc_ast_pretty",
|
||||
|
@ -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"
|
||||
|
@ -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 }
|
||||
atty::is(atty::Stream::Stdout)
|
||||
}
|
||||
|
||||
#[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
|
||||
}
|
||||
}
|
||||
|
||||
// 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) {
|
||||
|
@ -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);
|
||||
@ -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(),
|
||||
};
|
||||
|
||||
@ -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);
|
||||
}
|
||||
@ -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,
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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,
|
||||
);
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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")]
|
||||
|
@ -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)]
|
||||
|
@ -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];
|
||||
|
@ -1 +0,0 @@
|
||||
pub struct Wrap<A>(pub A);
|
@ -1,9 +0,0 @@
|
||||
// run-pass
|
||||
// aux-build:issue-10031-aux.rs
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
extern crate issue_10031_aux;
|
||||
|
||||
pub fn main() {
|
||||
let _ = issue_10031_aux::Wrap(());
|
||||
}
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
13
src/test/ui/terminal-width/tabs-trimming.rs
Normal file
13
src/test/ui/terminal-width/tabs-trimming.rs
Normal file
@ -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),
|
||||
}
|
||||
}
|
12
src/test/ui/terminal-width/tabs-trimming.stderr
Normal file
12
src/test/ui/terminal-width/tabs-trimming.stderr
Normal file
@ -0,0 +1,12 @@
|
||||
error[E0408]: variable `v` is not bound in all patterns
|
||||
--> $DIR/tabs-trimming.rs:9:16
|
||||
|
|
||||
LL | ... v @ 1 | 2 | 3 => panic!("You gave me too little money {}", v), // Long text here: TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT...
|
||||
| - ^ ^ pattern doesn't bind `v`
|
||||
| | |
|
||||
| | pattern doesn't bind `v`
|
||||
| variable not in all patterns
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0408`.
|
Loading…
Reference in New Issue
Block a user