diff --git a/src/doc/book b/src/doc/book index ef8bb568035de..5c5cfd2e94cd4 160000 --- a/src/doc/book +++ b/src/doc/book @@ -1 +1 @@ -Subproject commit ef8bb568035ded8ddfa30a9309026638cc3c8136 +Subproject commit 5c5cfd2e94cd42632798d9bd3d1116133e128ac9 diff --git a/src/doc/edition-guide b/src/doc/edition-guide index 6601cab466659..1a2390247ad6d 160000 --- a/src/doc/edition-guide +++ b/src/doc/edition-guide @@ -1 +1 @@ -Subproject commit 6601cab4666596494a569f94aa63b7b3230e9769 +Subproject commit 1a2390247ad6d08160e0dd74f40a01a9578659c2 diff --git a/src/doc/embedded-book b/src/doc/embedded-book index c262349302822..9493b7d4dc97e 160000 --- a/src/doc/embedded-book +++ b/src/doc/embedded-book @@ -1 +1 @@ -Subproject commit c26234930282210849256e4ecab925f0f2daf3be +Subproject commit 9493b7d4dc97eda439bd8780f05ad7b234cd1cd7 diff --git a/src/doc/nomicon b/src/doc/nomicon index 8be35b201f9cf..3e6e1001dc6e0 160000 --- a/src/doc/nomicon +++ b/src/doc/nomicon @@ -1 +1 @@ -Subproject commit 8be35b201f9cf0a4c3fcc96c83ac21671dcf3112 +Subproject commit 3e6e1001dc6e095dbd5c88005e80969f60e384e1 diff --git a/src/doc/reference b/src/doc/reference index d8dfe1b005c03..e1157538e86d8 160000 --- a/src/doc/reference +++ b/src/doc/reference @@ -1 +1 @@ -Subproject commit d8dfe1b005c03584cd7adc4bfb72b005e7e84744 +Subproject commit e1157538e86d83df0cf95d5e33bd943f80d0248f diff --git a/src/doc/rust-by-example b/src/doc/rust-by-example index b7ac1bc76b7d0..1d59403cb5269 160000 --- a/src/doc/rust-by-example +++ b/src/doc/rust-by-example @@ -1 +1 @@ -Subproject commit b7ac1bc76b7d02a43c83b3a931d226f708aa1ff4 +Subproject commit 1d59403cb5269c190cc52a95584ecc280345495a diff --git a/src/liballoc/tests/lib.rs b/src/liballoc/tests/lib.rs index c1ae67a1a339f..3fdee8bbfdf10 100644 --- a/src/liballoc/tests/lib.rs +++ b/src/liballoc/tests/lib.rs @@ -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}; diff --git a/src/liballoc/vec.rs b/src/liballoc/vec.rs index a27a13847d6a2..f5f8d88829f5f 100644 --- a/src/liballoc/vec.rs +++ b/src/liballoc/vec.rs @@ -1054,7 +1054,7 @@ impl Vec { /// /// ``` /// 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]); /// ``` /// @@ -1696,14 +1696,13 @@ impl Vec { /// # 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(&mut self, item: &V) -> Option where T: PartialEq, diff --git a/src/librustc/dep_graph/serialized.rs b/src/librustc/dep_graph/serialized.rs index 640877d3d55c3..45ef52dbf39c2 100644 --- a/src/librustc/dep_graph/serialized.rs +++ b/src/librustc/dep_graph/serialized.rs @@ -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 { .. } diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index ce8263f81a72f..37761c17f5243 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -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)] diff --git a/src/librustc/middle/region.rs b/src/librustc/middle/region.rs index b2a5efca92df3..9e9c8bd846473 100644 --- a/src/librustc/middle/region.rs +++ b/src/librustc/middle/region.rs @@ -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}; diff --git a/src/librustc/ty/print/obsolete.rs b/src/librustc/ty/print/obsolete.rs index 618c23ecc6e8a..7605d44c7f30f 100644 --- a/src/librustc/ty/print/obsolete.rs +++ b/src/librustc/ty/print/obsolete.rs @@ -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) { diff --git a/src/librustc_error_codes/error_codes/E0178.md b/src/librustc_error_codes/error_codes/E0178.md index 07980ad83f1b5..0c6f918632f47 100644 --- a/src/librustc_error_codes/error_codes/E0178.md +++ b/src/librustc_error_codes/error_codes/E0178.md @@ -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! } ``` diff --git a/src/librustc_errors/emitter.rs b/src/librustc_errors/emitter.rs index 541b89e6fce5f..526b4e2971bef 100644 --- a/src/librustc_errors/emitter.rs +++ b/src/librustc_errors/emitter.rs @@ -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 { @@ -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, ); @@ -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, ); @@ -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; } diff --git a/src/librustc_hir/hir_id.rs b/src/librustc_hir/hir_id.rs index 462946411718b..6d2ec44576353 100644 --- a/src/librustc_hir/hir_id.rs +++ b/src/librustc_hir/hir_id.rs @@ -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 diff --git a/src/librustc_index/vec.rs b/src/librustc_index/vec.rs index 1f6a330cdc235..d14bafb44fd5b 100644 --- a/src/librustc_index/vec.rs +++ b/src/librustc_index/vec.rs @@ -120,13 +120,13 @@ 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) } } @@ -134,7 +134,7 @@ macro_rules! newtype_index { $v fn from_u32(value: u32) -> Self { assert!(value <= $max); unsafe { - $type::from_u32_unchecked(value) + Self::from_u32_unchecked(value) } } @@ -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. @@ -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] @@ -204,39 +204,39 @@ macro_rules! newtype_index { #[inline] fn steps_between(start: &Self, end: &Self) -> Option { ::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 { - 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 { - Idx::index(*self).checked_sub(u).map(Self::new) + Self::index(*self).checked_sub(u).map(Self::from_usize) } } @@ -257,14 +257,14 @@ macro_rules! newtype_index { impl From for $type { #[inline] fn from(value: usize) -> Self { - $type::from_usize(value) + Self::from_usize(value) } } impl From for $type { #[inline] fn from(value: u32) -> Self { - $type::from_u32(value) + Self::from_u32(value) } } @@ -409,7 +409,7 @@ macro_rules! newtype_index { (@decodable $type:ident) => ( impl ::rustc_serialize::Decodable for $type { fn decode(d: &mut D) -> Result { - d.read_u32().map(Self::from) + d.read_u32().map(Self::from_u32) } } ); @@ -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])*] @@ -839,3 +839,6 @@ impl FnMut<(usize,)> for IntoIdx { I::new(n) } } + +#[cfg(test)] +mod tests; diff --git a/src/librustc_index/vec/tests.rs b/src/librustc_index/vec/tests.rs new file mode 100644 index 0000000000000..15c43c72c7b37 --- /dev/null +++ b/src/librustc_index/vec/tests.rs @@ -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::(), 4); + // Uses 0xFFFF_FFFB + assert_eq!(size_of::>(), 4); + // Uses 0xFFFF_FFFC + assert_eq!(size_of::>>(), 4); + // Uses 0xFFFF_FFFD + assert_eq!(size_of::>>>(), 4); + // Uses 0xFFFF_FFFE + assert_eq!(size_of::>>>>(), 4); + // Uses 0xFFFF_FFFF + assert_eq!(size_of::>>>>>(), 4); + // Uses a tag + assert_eq!(size_of::>>>>>>(), 8); +} + +#[test] +fn range_iterator_iterates_forwards() { + let range = MyIdx::from_u32(1)..MyIdx::from_u32(4); + assert_eq!( + range.collect::>(), + [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::>(), + [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))); +} diff --git a/src/librustc_lint/nonstandard_style.rs b/src/librustc_lint/nonstandard_style.rs index 6df2740bee848..d50c048301042 100644 --- a/src/librustc_lint/nonstandard_style.rs +++ b/src/librustc_lint/nonstandard_style.rs @@ -143,6 +143,12 @@ impl EarlyLintPass for NonCamelCaseTypes { } } + fn check_trait_item(&mut self, cx: &EarlyContext<'_>, it: &ast::AssocItem) { + if let ast::AssocItemKind::TyAlias(..) = it.kind { + self.check_case(cx, "associated type", &it.ident); + } + } + fn check_variant(&mut self, cx: &EarlyContext<'_>, v: &ast::Variant) { self.check_case(cx, "variant", &v.ident); } diff --git a/src/librustc_mir/borrow_check/constraints/mod.rs b/src/librustc_mir/borrow_check/constraints/mod.rs index 48defecd28cb0..ef70b127ac5bd 100644 --- a/src/librustc_mir/borrow_check/constraints/mod.rs +++ b/src/librustc_mir/borrow_check/constraints/mod.rs @@ -1,7 +1,7 @@ use rustc::mir::ConstraintCategory; use rustc::ty::RegionVid; use rustc_data_structures::graph::scc::Sccs; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::IndexVec; use std::fmt; use std::ops::Index; diff --git a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs index 0d343e76618b4..9a301a6ad32a8 100644 --- a/src/librustc_mir/borrow_check/diagnostics/region_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/region_errors.rs @@ -800,7 +800,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { // If there is a static predicate, then the only sensible suggestion is to replace // fr with `'static`. if has_static_predicate { - diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str,)); + diag.help(&format!("consider replacing `{}` with `{}`", fr_name, static_str)); } else { // Otherwise, we should suggest adding a constraint on the return type. let span = infcx.tcx.def_span(*did); @@ -810,7 +810,12 @@ impl<'tcx> RegionInferenceContext<'tcx> { } else { "'_".to_string() }; - + let suggestion = if snippet.ends_with(";") { + // `type X = impl Trait;` + format!("{} + {};", &snippet[..snippet.len() - 1], suggestable_fr_name) + } else { + format!("{} + {}", snippet, suggestable_fr_name) + }; diag.span_suggestion( span, &format!( @@ -818,7 +823,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { `{}`, add `{}` as a bound", fr_name, suggestable_fr_name, ), - format!("{} + {}", snippet, suggestable_fr_name), + suggestion, Applicability::MachineApplicable, ); } diff --git a/src/librustc_mir/borrow_check/member_constraints.rs b/src/librustc_mir/borrow_check/member_constraints.rs index 53fa5b1269849..c95919685bbc7 100644 --- a/src/librustc_mir/borrow_check/member_constraints.rs +++ b/src/librustc_mir/borrow_check/member_constraints.rs @@ -2,7 +2,7 @@ use crate::rustc::ty::{self, Ty}; use rustc::infer::region_constraints::MemberConstraint; use rustc_data_structures::fx::FxHashMap; use rustc_hir::def_id::DefId; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::IndexVec; use rustc_span::Span; use std::hash::Hash; use std::ops::Index; diff --git a/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs index 7bf355ddbf612..8155aa0ee000a 100644 --- a/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs +++ b/src/librustc_mir/borrow_check/type_check/liveness/local_use_map.rs @@ -1,7 +1,7 @@ use rustc::mir::visit::{PlaceContext, Visitor}; use rustc::mir::{Local, Location, ReadOnlyBodyAndCache}; use rustc_data_structures::vec_linked_list as vll; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::IndexVec; use crate::util::liveness::{categorize, DefUse}; diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 30eccebd3315f..8d51cb2391234 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -4,7 +4,7 @@ use rustc::ty::{self, TyCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_index::bit_set::BitSet; -use rustc_index::vec::{Idx, IndexVec}; +use rustc_index::vec::IndexVec; use crate::borrow_check::{ places_conflict, BorrowData, BorrowSet, PlaceConflictBias, PlaceExt, RegionInferenceContext, diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 6450762d351b1..e5cddaf6c66f2 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -2,7 +2,7 @@ use core::slice::Iter; use rustc::mir::*; use rustc::ty::{ParamEnv, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; -use rustc_index::vec::{Enumerated, Idx, IndexVec}; +use rustc_index::vec::{Enumerated, IndexVec}; use rustc_span::Span; use smallvec::SmallVec; diff --git a/src/librustc_session/node_id.rs b/src/librustc_session/node_id.rs index 5e51c5a92ccc4..9fefe908e578e 100644 --- a/src/librustc_session/node_id.rs +++ b/src/librustc_session/node_id.rs @@ -1,4 +1,3 @@ -use rustc_index::vec::Idx; use rustc_serialize::{Decoder, Encoder}; use rustc_span::ExpnId; use std::fmt; diff --git a/src/librustc_span/symbol.rs b/src/librustc_span/symbol.rs index fea72744d31e4..40abc8b2179b8 100644 --- a/src/librustc_span/symbol.rs +++ b/src/librustc_span/symbol.rs @@ -5,7 +5,6 @@ use arena::DroplessArena; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::stable_hasher::{HashStable, StableHasher, ToStableHashKey}; -use rustc_index::vec::Idx; use rustc_macros::{symbols, HashStable_Generic}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; use rustc_serialize::{UseSpecializedDecodable, UseSpecializedEncodable}; diff --git a/src/librustdoc/html/format.rs b/src/librustdoc/html/format.rs index 2580bbf982b04..6434dccdfc75b 100644 --- a/src/librustdoc/html/format.rs +++ b/src/librustdoc/html/format.rs @@ -15,6 +15,7 @@ use rustc_hir::def_id::DefId; use rustc_target::spec::abi::Abi; use crate::clean::{self, PrimitiveType}; +use crate::html::escape::Escape; use crate::html::item_type::ItemType; use crate::html::render::{self, cache, CURRENT_DEPTH}; @@ -314,8 +315,14 @@ impl clean::Lifetime { } impl clean::Constant { - crate fn print(&self) -> &str { - &self.expr + crate fn print(&self) -> impl fmt::Display + '_ { + display_fn(move |f| { + if f.alternate() { + f.write_str(&self.expr) + } else { + write!(f, "{}", Escape(&self.expr)) + } + }) } } @@ -689,7 +696,11 @@ fn fmt_type(t: &clean::Type, f: &mut fmt::Formatter<'_>, use_absolute: bool) -> clean::Array(ref t, ref n) => { primitive_link(f, PrimitiveType::Array, "[")?; fmt::Display::fmt(&t.print(), f)?; - primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) + if f.alternate() { + primitive_link(f, PrimitiveType::Array, &format!("; {}]", n)) + } else { + primitive_link(f, PrimitiveType::Array, &format!("; {}]", Escape(n))) + } } clean::Never => primitive_link(f, PrimitiveType::Never, "!"), clean::RawPointer(m, ref t) => { diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 025257b801fb6..a01e2f793948e 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -2280,7 +2280,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons ); if c.value.is_some() || c.is_literal { - write!(w, " = {expr};", expr = c.expr); + write!(w, " = {expr};", expr = Escape(&c.expr)); } else { write!(w, ";"); } @@ -2293,7 +2293,7 @@ fn item_constant(w: &mut Buffer, cx: &Context, it: &clean::Item, c: &clean::Cons if value_lowercase != expr_lowercase && value_lowercase.trim_end_matches("i32") != expr_lowercase { - write!(w, " // {value}", value = value); + write!(w, " // {value}", value = Escape(value)); } } } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 16917181471f5..eeaac1d8c7431 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -10,7 +10,6 @@ #![feature(nll)] #![feature(set_stdio)] #![feature(test)] -#![feature(vec_remove_item)] #![feature(ptr_offset_from)] #![feature(crate_visibility_modifier)] #![feature(const_fn)] diff --git a/src/librustdoc/visit_ast.rs b/src/librustdoc/visit_ast.rs index d7bf8d157d21a..5fa9270959cca 100644 --- a/src/librustdoc/visit_ast.rs +++ b/src/librustdoc/visit_ast.rs @@ -10,7 +10,7 @@ use rustc_hir::def_id::{DefId, LOCAL_CRATE}; use rustc_hir::Node; use rustc_span::hygiene::MacroKind; use rustc_span::source_map::Spanned; -use rustc_span::symbol::sym; +use rustc_span::symbol::{kw, sym}; use rustc_span::{self, Span}; use syntax::ast; @@ -514,16 +514,20 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> { om.statics.push(s); } hir::ItemKind::Const(type_, expr) => { - let s = Constant { - type_, - expr, - id: item.hir_id, - name: ident.name, - attrs: &item.attrs, - whence: item.span, - vis: &item.vis, - }; - om.constants.push(s); + // Underscore constants do not correspond to a nameable item and + // so are never useful in documentation. + if ident.name != kw::Underscore { + let s = Constant { + type_, + expr, + id: item.hir_id, + name: ident.name, + attrs: &item.attrs, + whence: item.span, + vis: &item.vis, + }; + om.constants.push(s); + } } hir::ItemKind::Trait(is_auto, unsafety, ref generics, ref bounds, ref item_ids) => { let items = item_ids.iter().map(|ti| self.cx.tcx.hir().trait_item(ti.id)).collect(); diff --git a/src/libstd/net/tcp.rs b/src/libstd/net/tcp.rs index c33f98bdd8329..5023d69240893 100644 --- a/src/libstd/net/tcp.rs +++ b/src/libstd/net/tcp.rs @@ -63,14 +63,13 @@ pub struct TcpStream(net_imp::TcpStream); /// # Examples /// /// ```no_run -/// # use std::io; /// use std::net::{TcpListener, TcpStream}; /// /// fn handle_client(stream: TcpStream) { /// // ... /// } /// -/// fn main() -> io::Result<()> { +/// fn main() -> std::io::Result<()> { /// let listener = TcpListener::bind("127.0.0.1:80")?; /// /// // accept connections and process them serially diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index b17418911380d..0dc43c7e6510a 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -1072,6 +1072,19 @@ impl ThreadId { ThreadId(NonZeroU64::new(id).unwrap()) } } + + /// This returns a numeric identifier for the thread identified by this + /// `ThreadId`. + /// + /// As noted in the documentation for the type itself, it is essentially an + /// opaque ID, but is guaranteed to be unique for each thread. The returned + /// value is entirely opaque -- only equality testing is stable. Note that + /// it is not guaranteed which values new threads will return, and this may + /// change across Rust versions. + #[unstable(feature = "thread_id_value", issue = "67939")] + pub fn as_u64(&self) -> u64 { + self.0.get() + } } //////////////////////////////////////////////////////////////////////////////// diff --git a/src/test/rustdoc/const-generics/const-impl.rs b/src/test/rustdoc/const-generics/const-impl.rs index 819adfeb9c775..7361b22b74798 100644 --- a/src/test/rustdoc/const-generics/const-impl.rs +++ b/src/test/rustdoc/const-generics/const-impl.rs @@ -30,3 +30,10 @@ impl VSet { Self { inner: Vec::new() } } } + +pub struct Escape; + +// @has foo/struct.Escape.html '//h3[@id="impl"]/code' 'impl Escape<{ r#""# }>' +impl Escape<{ r#""# }> { + pub fn f() {} +} diff --git a/src/test/rustdoc/const-underscore.rs b/src/test/rustdoc/const-underscore.rs new file mode 100644 index 0000000000000..0d4809409f3a2 --- /dev/null +++ b/src/test/rustdoc/const-underscore.rs @@ -0,0 +1,7 @@ +// compile-flags: --document-private-items + +// @!has const_underscore/constant._.html +const _: () = { + #[no_mangle] + extern "C" fn implementation_detail() {} +}; diff --git a/src/test/rustdoc/show-const-contents.rs b/src/test/rustdoc/show-const-contents.rs index 6d95f7827a1d7..e84f6e52c75aa 100644 --- a/src/test/rustdoc/show-const-contents.rs +++ b/src/test/rustdoc/show-const-contents.rs @@ -62,3 +62,6 @@ macro_rules! int_module { // @has show_const_contents/constant.MIN.html '= i16::min_value(); // -32_768i16' int_module!(i16); + +// @has show_const_contents/constant.ESCAPE.html //pre '= r#""#;' +pub const ESCAPE: &str = r#""#; diff --git a/src/test/ui-fulldeps/newtype_index.rs b/src/test/ui-fulldeps/newtype_index.rs deleted file mode 100644 index fe68b394e5a5c..0000000000000 --- a/src/test/ui-fulldeps/newtype_index.rs +++ /dev/null @@ -1,22 +0,0 @@ -// run-pass - -#![feature(rustc_private)] - -extern crate rustc_index; -extern crate serialize as rustc_serialize; - -use rustc_index::{newtype_index, vec::Idx}; - -newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA }); - -use std::mem::size_of; - -fn main() { - assert_eq!(size_of::(), 4); - assert_eq!(size_of::>(), 4); - assert_eq!(size_of::>>(), 4); - assert_eq!(size_of::>>>(), 4); - assert_eq!(size_of::>>>>(), 4); - assert_eq!(size_of::>>>>>(), 4); - assert_eq!(size_of::>>>>>>(), 8); -} diff --git a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr index 4c38f0a8a914d..5957ecbdc5faa 100644 --- a/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr +++ b/src/test/ui/impl-trait/multiple-lifetimes/error-handling.stderr @@ -7,7 +7,7 @@ LL | fn foo<'a, 'b, 'c>(x: &'static i32, mut y: &'a i32) -> E<'b, 'c> { = help: consider replacing `'a` with `'static` help: to allow this `impl Trait` to capture borrowed data with lifetime `'a`, add `'a` as a bound | -LL | type E<'a, 'b> = impl Sized; + 'a +LL | type E<'a, 'b> = impl Sized + 'a; | error: aborting due to previous error diff --git a/src/test/ui/issues/issue-17732.rs b/src/test/ui/issues/issue-17732.rs index 5e11fc4fcfb58..8f63d5baef875 100644 --- a/src/test/ui/issues/issue-17732.rs +++ b/src/test/ui/issues/issue-17732.rs @@ -1,5 +1,6 @@ // check-pass #![allow(dead_code)] +#![allow(non_camel_case_types)] // pretty-expanded FIXME #23616 trait Person { diff --git a/src/test/ui/issues/issue-35600.rs b/src/test/ui/issues/issue-35600.rs index 9d74726d279e5..f0bab6010d724 100644 --- a/src/test/ui/issues/issue-35600.rs +++ b/src/test/ui/issues/issue-35600.rs @@ -1,5 +1,7 @@ // run-pass +#![allow(non_camel_case_types)] #![allow(unused_variables)] + trait Foo { type bar; fn bar(); diff --git a/src/test/ui/lint/lint-non-camel-case-types.rs b/src/test/ui/lint/lint-non-camel-case-types.rs index d3b119a944109..acd5c5df9e8f6 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.rs +++ b/src/test/ui/lint/lint-non-camel-case-types.rs @@ -23,6 +23,7 @@ enum Foo5 { } trait foo6 { //~ ERROR trait `foo6` should have an upper camel case name + type foo7; //~ ERROR associated type `foo7` should have an upper camel case name fn dummy(&self) { } } diff --git a/src/test/ui/lint/lint-non-camel-case-types.stderr b/src/test/ui/lint/lint-non-camel-case-types.stderr index 177f8c8fe9b63..f82eefed4368a 100644 --- a/src/test/ui/lint/lint-non-camel-case-types.stderr +++ b/src/test/ui/lint/lint-non-camel-case-types.stderr @@ -46,11 +46,17 @@ error: trait `foo6` should have an upper camel case name LL | trait foo6 { | ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo6` +error: associated type `foo7` should have an upper camel case name + --> $DIR/lint-non-camel-case-types.rs:26:10 + | +LL | type foo7; + | ^^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo7` + error: type parameter `ty` should have an upper camel case name - --> $DIR/lint-non-camel-case-types.rs:29:6 + --> $DIR/lint-non-camel-case-types.rs:30:6 | LL | fn f(_: ty) {} | ^^ help: convert the identifier to upper camel case: `Ty` -error: aborting due to 8 previous errors +error: aborting due to 9 previous errors diff --git a/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.rs b/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.rs new file mode 100644 index 0000000000000..68aadcf605384 --- /dev/null +++ b/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.rs @@ -0,0 +1,8 @@ +// Regression test for issue #67690 +// Rustc endless loop out-of-memory and consequent SIGKILL in generic new type + +// check-pass +pub type T = P; +//~^ WARN bounds on generic parameters are not enforced in type aliases + +fn main() {} diff --git a/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.stderr b/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.stderr new file mode 100644 index 0000000000000..37b51b50b964e --- /dev/null +++ b/src/test/ui/type/issue-67690-type-alias-bound-diagnostic-crash.stderr @@ -0,0 +1,12 @@ +warning: bounds on generic parameters are not enforced in type aliases + --> $DIR/issue-67690-type-alias-bound-diagnostic-crash.rs:5:15 + | +LL | pub type T = P; + | ^^^^ ^^^^ ^^^^ + | + = note: `#[warn(type_alias_bounds)]` on by default +help: the bound will not be checked when the type alias is used, and should be removed + | +LL | pub type T

= P; + | -- + diff --git a/src/test/ui/type/type-alias-bounds.rs b/src/test/ui/type/type-alias-bounds.rs index 06705a2ebf5dd..65b79650d4d72 100644 --- a/src/test/ui/type/type-alias-bounds.rs +++ b/src/test/ui/type/type-alias-bounds.rs @@ -1,6 +1,6 @@ // Test `ignored_generic_bounds` lint warning about bounds in type aliases. -// build-pass (FIXME(62277): could be check-pass?) +// check-pass #![allow(dead_code)] use std::rc::Rc; diff --git a/src/test/ui/type/type-alias-bounds.stderr b/src/test/ui/type/type-alias-bounds.stderr index c381d30c64f14..e4d3753f8a59a 100644 --- a/src/test/ui/type/type-alias-bounds.stderr +++ b/src/test/ui/type/type-alias-bounds.stderr @@ -8,7 +8,7 @@ LL | type SVec = Vec; help: the bound will not be checked when the type alias is used, and should be removed | LL | type SVec = Vec; - | -- -- + | -- warning: where clauses are not enforced in type aliases --> $DIR/type-alias-bounds.rs:10:21 @@ -30,7 +30,7 @@ LL | type VVec<'b, 'a: 'b + 'b> = (&'b u32, Vec<&'a i32>); help: the bound will not be checked when the type alias is used, and should be removed | LL | type VVec<'b, 'a> = (&'b u32, Vec<&'a i32>); - | -- -- + | -- warning: bounds on generic parameters are not enforced in type aliases --> $DIR/type-alias-bounds.rs:14:18 @@ -41,7 +41,7 @@ LL | type WVec<'b, T: 'b + 'b> = (&'b u32, Vec); help: the bound will not be checked when the type alias is used, and should be removed | LL | type WVec<'b, T> = (&'b u32, Vec); - | -- -- + | -- warning: where clauses are not enforced in type aliases --> $DIR/type-alias-bounds.rs:16:25 diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 487c1d5fb93a6..da1e3760e010d 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -1,6 +1,5 @@ #![crate_name = "compiletest"] #![feature(test)] -#![feature(vec_remove_item)] #![deny(warnings)] extern crate test;