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 13 pull requests #67964

Merged
merged 30 commits into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
097126e
Omit underscore constants from rustdoc
dtolnay Jan 4, 2020
12545c7
Handle multiple error fix suggestions carefuly
lbonn Jan 4, 2020
e2305d0
rustdoc: HTML escape const values
ollie27 Jan 5, 2020
8f94d9b
Fix ICE in const pretty printing and resolve FIXME
varkor Jan 6, 2020
e6d95ce
Formatting an example for method Vec.retain
mgrachev Jan 6, 2020
24c6cd8
stabilise remove_item
Dylan-DPC Dec 30, 2019
0a739ce
remove usage of feature gate
Dylan-DPC Dec 30, 2019
99fda5c
Clean up E0178 explanation
GuillaumeGomez Jan 6, 2020
a7727c5
fire "non_camel_case_types" for associated types
euclio Jan 6, 2020
6bec8e9
stabilise it
Dylan-DPC Jan 6, 2020
d9a7db9
Add an unstable conversion from thread ID to u64
Mark-Simulacrum Dec 23, 2019
0113cac
Missing module std in example.
Stromberg90 Jan 6, 2020
a852941
Removed module usage.
Stromberg90 Jan 6, 2020
503d06b
oh the one that was left behind
Dylan-DPC Jan 6, 2020
9462c8b
Improve hygiene of `newtype_index`
matthewjasper Jan 5, 2020
2905f14
Account for `type X = impl Trait;` in lifetime suggestion
estebank Dec 28, 2019
518f50c
Update books
ehuss Jan 7, 2020
c671fc1
Rollup merge of #67566 - Mark-Simulacrum:thread-id-u64, r=alexcrichton
JohnTitor Jan 7, 2020
3cce950
Rollup merge of #67671 - estebank:type-impl-trait, r=davidtwco
JohnTitor Jan 7, 2020
4ed415b
Rollup merge of #67727 - Dylan-DPC:stabilise/remove_item, r=alexcrichton
JohnTitor Jan 7, 2020
74ca7c7
Rollup merge of #67877 - dtolnay:const-_, r=nagisa
JohnTitor Jan 7, 2020
6d9913d
Rollup merge of #67880 - lbonn:fix/multi-substs, r=petrochenkov
JohnTitor Jan 7, 2020
9ef3b2c
Rollup merge of #67898 - matthewjasper:newtype-index-hygiene, r=Centril
JohnTitor Jan 7, 2020
c07204b
Rollup merge of #67908 - ollie27:rustdoc_const_html_escape, r=Guillau…
JohnTitor Jan 7, 2020
318d6c2
Rollup merge of #67909 - varkor:obsolete-const-print, r=davidtwco
JohnTitor Jan 7, 2020
2c25ad5
Rollup merge of #67929 - mgrachev:patch-1, r=jonas-schievink
JohnTitor Jan 7, 2020
1e7a6a8
Rollup merge of #67934 - GuillaumeGomez:clean-up-e0178, r=Dylan-DPC
JohnTitor Jan 7, 2020
b065031
Rollup merge of #67936 - euclio:assoc-type-bad-style, r=Centril
JohnTitor Jan 7, 2020
05797b1
Rollup merge of #67943 - Stromberg90:patch-1, r=jonas-schievink
JohnTitor Jan 7, 2020
23d9788
Rollup merge of #67962 - ehuss:update-books, r=ehuss
JohnTitor Jan 7, 2020
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
2 changes: 1 addition & 1 deletion src/doc/edition-guide
2 changes: 1 addition & 1 deletion src/doc/embedded-book
2 changes: 1 addition & 1 deletion src/doc/nomicon
Submodule nomicon updated 1 files
+1 −3 src/phantom-data.md
2 changes: 1 addition & 1 deletion src/doc/reference
1 change: 0 additions & 1 deletion src/liballoc/tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#![feature(associated_type_bounds)]
#![feature(binary_heap_into_iter_sorted)]
#![feature(binary_heap_drain_sorted)]
#![feature(vec_remove_item)]

use std::collections::hash_map::DefaultHasher;
use std::hash::{Hash, Hasher};
Expand Down
5 changes: 2 additions & 3 deletions src/liballoc/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1054,7 +1054,7 @@ impl<T> Vec<T> {
///
/// ```
/// let mut vec = vec![1, 2, 3, 4];
/// vec.retain(|&x| x%2 == 0);
/// vec.retain(|&x| x % 2 == 0);
/// assert_eq!(vec, [2, 4]);
/// ```
///
Expand Down Expand Up @@ -1696,14 +1696,13 @@ impl<T> Vec<T> {
/// # Examples
///
/// ```
/// # #![feature(vec_remove_item)]
/// let mut vec = vec![1, 2, 3, 1];
///
/// vec.remove_item(&1);
///
/// assert_eq!(vec, vec![2, 3, 1]);
/// ```
#[unstable(feature = "vec_remove_item", reason = "recently added", issue = "40062")]
#[stable(feature = "vec_remove_item", since = "1.42.0")]
pub fn remove_item<V>(&mut self, item: &V) -> Option<T>
where
T: PartialEq<V>,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::dep_graph::DepNode;
use crate::ich::Fingerprint;
use rustc_index::vec::{Idx, IndexVec};
use rustc_index::vec::IndexVec;

rustc_index::newtype_index! {
pub struct SerializedDepNodeIndex { .. }
Expand Down
1 change: 0 additions & 1 deletion src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
#![feature(thread_local)]
#![feature(trace_macros)]
#![feature(trusted_len)]
#![feature(vec_remove_item)]
#![feature(stmt_expr_attributes)]
#![feature(integer_atomics)]
#![feature(test)]
Expand Down
1 change: 0 additions & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use rustc_hir::Node;

use rustc_data_structures::fx::FxHashMap;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_index::vec::Idx;
use rustc_macros::HashStable;
use rustc_span::{Span, DUMMY_SP};

Expand Down
17 changes: 5 additions & 12 deletions src/librustc/ty/print/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,19 +166,12 @@ impl DefPathBasedNames<'tcx> {
}

// Pushes the the name of the specified const to the provided string.
// If `debug` is true, usually-unprintable consts (such as `Infer`) will be printed,
// as well as the unprintable types of constants (see `push_type_name` for more details).
pub fn push_const_name(&self, c: &Const<'tcx>, output: &mut String, debug: bool) {
if let ty::ConstKind::Value(_) = c.val {
// FIXME(const_generics): we could probably do a better job here.
write!(output, "{:?}", c).unwrap()
} else if debug {
write!(output, "{:?}", c).unwrap()
} else {
bug!("DefPathBasedNames: trying to create const name for unexpected const: {:?}", c,);
}
// If `debug` is true, the unprintable types of constants will be printed with `fmt::Debug`
// (see `push_type_name` for more details).
pub fn push_const_name(&self, ct: &Const<'tcx>, output: &mut String, debug: bool) {
write!(output, "{}", ct).unwrap();
output.push_str(": ");
self.push_type_name(c.ty, output, debug);
self.push_type_name(ct.ty, output, debug);
}

pub fn push_def_path(&self, def_id: DefId, output: &mut String) {
Expand Down
25 changes: 18 additions & 7 deletions src/librustc_error_codes/error_codes/E0178.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
In types, the `+` type operator has low precedence, so it is often necessary
to use parentheses.
The `+` type operator was used in an ambiguous context.

For example:
Erroneous code example:

```compile_fail,E0178
trait Foo {}

struct Bar<'a> {
w: &'a Foo + Copy, // error, use &'a (Foo + Copy)
x: &'a Foo + 'a, // error, use &'a (Foo + 'a)
y: &'a mut Foo + 'a, // error, use &'a mut (Foo + 'a)
z: fn() -> Foo + 'a, // error, use fn() -> (Foo + 'a)
x: &'a Foo + 'a, // error!
y: &'a mut Foo + 'a, // error!
z: fn() -> Foo + 'a, // error!
}
```

In types, the `+` type operator has low precedence, so it is often necessary
to use parentheses:

```
trait Foo {}

struct Bar<'a> {
x: &'a (Foo + 'a), // ok!
y: &'a mut (Foo + 'a), // ok!
z: fn() -> (Foo + 'a), // ok!
}
```

Expand Down
18 changes: 13 additions & 5 deletions src/librustc_errors/emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ impl EmitterWriter {

// This offset and the ones below need to be signed to account for replacement code
// that is shorter than the original code.
let mut offset: isize = 0;
let mut offsets: Vec<(usize, isize)> = Vec::new();
// Only show an underline in the suggestions if the suggestion is not the
// entirety of the code being shown and the displayed code is not multiline.
if show_underline {
Expand All @@ -1550,12 +1550,19 @@ impl EmitterWriter {
.map(|ch| unicode_width::UnicodeWidthChar::width(ch).unwrap_or(1))
.sum();

let offset: isize = offsets
.iter()
.filter_map(
|(start, v)| if span_start_pos <= *start { None } else { Some(v) },
)
.sum();
let underline_start = (span_start_pos + start) as isize + offset;
let underline_end = (span_start_pos + start + sub_len) as isize + offset;
assert!(underline_start >= 0 && underline_end >= 0);
for p in underline_start..underline_end {
buffer.putc(
row_num,
max_line_num_len + 3 + p as usize,
((max_line_num_len + 3) as isize + p) as usize,
'^',
Style::UnderlinePrimary,
);
Expand All @@ -1565,7 +1572,7 @@ impl EmitterWriter {
for p in underline_start - 1..underline_start + 1 {
buffer.putc(
row_num,
max_line_num_len + 3 + p as usize,
((max_line_num_len + 3) as isize + p) as usize,
'-',
Style::UnderlineSecondary,
);
Expand All @@ -1582,8 +1589,9 @@ impl EmitterWriter {
// length of the code to be substituted
let snippet_len = span_end_pos as isize - span_start_pos as isize;
// For multiple substitutions, use the position *after* the previous
// substitutions have happened.
offset += full_sub_len - snippet_len;
// substitutions have happened, only when further substitutions are
// located strictly after.
offsets.push((span_end_pos, full_sub_len - snippet_len));
}
row_num += 1;
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_hir/hir_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ impl fmt::Display for HirId {
rustc_data_structures::define_id_collections!(HirIdMap, HirIdSet, HirId);
rustc_data_structures::define_id_collections!(ItemLocalMap, ItemLocalSet, ItemLocalId);

use rustc_index::vec::Idx;
rustc_index::newtype_index! {
/// An `ItemLocalId` uniquely identifies something within a given "item-like";
/// that is, within a `hir::Item`, `hir::TraitItem`, or `hir::ImplItem`. There is no
Expand Down
43 changes: 23 additions & 20 deletions src/librustc_index/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,21 +120,21 @@ macro_rules! newtype_index {
impl $type {
$v const MAX_AS_U32: u32 = $max;

$v const MAX: $type = $type::from_u32_const($max);
$v const MAX: Self = Self::from_u32_const($max);

#[inline]
$v fn from_usize(value: usize) -> Self {
assert!(value <= ($max as usize));
unsafe {
$type::from_u32_unchecked(value as u32)
Self::from_u32_unchecked(value as u32)
}
}

#[inline]
$v fn from_u32(value: u32) -> Self {
assert!(value <= $max);
unsafe {
$type::from_u32_unchecked(value)
Self::from_u32_unchecked(value)
}
}

Expand All @@ -152,13 +152,13 @@ macro_rules! newtype_index {
];

unsafe {
$type { private: value }
Self { private: value }
}
}

#[inline]
$v const unsafe fn from_u32_unchecked(value: u32) -> Self {
$type { private: value }
Self { private: value }
}

/// Extracts the value of this index as an integer.
Expand All @@ -184,14 +184,14 @@ macro_rules! newtype_index {
type Output = Self;

fn add(self, other: usize) -> Self {
Self::new(self.index() + other)
Self::from_usize(self.index() + other)
}
}

impl Idx for $type {
impl $crate::vec::Idx for $type {
#[inline]
fn new(value: usize) -> Self {
Self::from(value)
Self::from_usize(value)
}

#[inline]
Expand All @@ -204,39 +204,39 @@ macro_rules! newtype_index {
#[inline]
fn steps_between(start: &Self, end: &Self) -> Option<usize> {
<usize as ::std::iter::Step>::steps_between(
&Idx::index(*start),
&Idx::index(*end),
&Self::index(*start),
&Self::index(*end),
)
}

#[inline]
fn replace_one(&mut self) -> Self {
::std::mem::replace(self, Self::new(1))
::std::mem::replace(self, Self::from_u32(1))
}

#[inline]
fn replace_zero(&mut self) -> Self {
::std::mem::replace(self, Self::new(0))
::std::mem::replace(self, Self::from_u32(0))
}

#[inline]
fn add_one(&self) -> Self {
Self::new(Idx::index(*self) + 1)
Self::from_usize(Self::index(*self) + 1)
}

#[inline]
fn sub_one(&self) -> Self {
Self::new(Idx::index(*self) - 1)
Self::from_usize(Self::index(*self) - 1)
}

#[inline]
fn add_usize(&self, u: usize) -> Option<Self> {
Idx::index(*self).checked_add(u).map(Self::new)
Self::index(*self).checked_add(u).map(Self::from_usize)
}

#[inline]
fn sub_usize(&self, u: usize) -> Option<Self> {
Idx::index(*self).checked_sub(u).map(Self::new)
Self::index(*self).checked_sub(u).map(Self::from_usize)
}
}

Expand All @@ -257,14 +257,14 @@ macro_rules! newtype_index {
impl From<usize> for $type {
#[inline]
fn from(value: usize) -> Self {
$type::from_usize(value)
Self::from_usize(value)
}
}

impl From<u32> for $type {
#[inline]
fn from(value: u32) -> Self {
$type::from_u32(value)
Self::from_u32(value)
}
}

Expand Down Expand Up @@ -409,7 +409,7 @@ macro_rules! newtype_index {
(@decodable $type:ident) => (
impl ::rustc_serialize::Decodable for $type {
fn decode<D: ::rustc_serialize::Decoder>(d: &mut D) -> Result<Self, D::Error> {
d.read_u32().map(Self::from)
d.read_u32().map(Self::from_u32)
}
}
);
Expand Down Expand Up @@ -500,7 +500,7 @@ macro_rules! newtype_index {
const $name:ident = $constant:expr,
$($tokens:tt)*) => (
$(#[doc = $doc])*
pub const $name: $type = $type::from_u32_const($constant);
$v const $name: $type = $type::from_u32_const($constant);
$crate::newtype_index!(
@derives [$($derives,)*]
@attrs [$(#[$attrs])*]
Expand Down Expand Up @@ -839,3 +839,6 @@ impl<I: Idx> FnMut<(usize,)> for IntoIdx<I> {
I::new(n)
}
}

#[cfg(test)]
mod tests;
51 changes: 51 additions & 0 deletions src/librustc_index/vec/tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#![allow(dead_code)]
newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });

#[test]
fn index_size_is_optimized() {
use std::mem::size_of;

assert_eq!(size_of::<MyIdx>(), 4);
// Uses 0xFFFF_FFFB
assert_eq!(size_of::<Option<MyIdx>>(), 4);
// Uses 0xFFFF_FFFC
assert_eq!(size_of::<Option<Option<MyIdx>>>(), 4);
// Uses 0xFFFF_FFFD
assert_eq!(size_of::<Option<Option<Option<MyIdx>>>>(), 4);
// Uses 0xFFFF_FFFE
assert_eq!(size_of::<Option<Option<Option<Option<MyIdx>>>>>(), 4);
// Uses 0xFFFF_FFFF
assert_eq!(size_of::<Option<Option<Option<Option<Option<MyIdx>>>>>>(), 4);
// Uses a tag
assert_eq!(size_of::<Option<Option<Option<Option<Option<Option<MyIdx>>>>>>>(), 8);
}

#[test]
fn range_iterator_iterates_forwards() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(
range.collect::<Vec<_>>(),
[MyIdx::from_u32(1), MyIdx::from_u32(2), MyIdx::from_u32(3)]
);
}

#[test]
fn range_iterator_iterates_backwards() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(
range.rev().collect::<Vec<_>>(),
[MyIdx::from_u32(3), MyIdx::from_u32(2), MyIdx::from_u32(1)]
);
}

#[test]
fn range_count_is_correct() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(range.count(), 3);
}

#[test]
fn range_size_hint_is_correct() {
let range = MyIdx::from_u32(1)..MyIdx::from_u32(4);
assert_eq!(range.size_hint(), (3, Some(3)));
}
Loading