Skip to content

Commit

Permalink
Auto merge of rust-lang#72187 - RalfJung:rollup-a7a9jdi, r=RalfJung
Browse files Browse the repository at this point in the history
Rollup of 12 pull requests

Successful merges:

 - rust-lang#71525 (`prefix` should not be mutable.)
 - rust-lang#71741 (Pointer printing: do not print 0 offset)
 - rust-lang#71870 (Be slightly more precise about any::type_name()'s guarantees.)
 - rust-lang#71909 (Document From trait for Option implementations)
 - rust-lang#71964 (Fix bootstrap failing on win32)
 - rust-lang#72137 (Clean up E0581 explanation)
 - rust-lang#72138 (Add doc comment for `rustc_middle::mir::mono::Linkage`)
 - rust-lang#72150 (Remove UnnormalizedProjection)
 - rust-lang#72151 (Update books)
 - rust-lang#72163 (docs: remove comment referencing non-existent method)
 - rust-lang#72169 (Clean up E0582 explanation)
 - rust-lang#72183 (Fix Arc::decr_strong_count doc test)

Failed merges:

r? @ghost
  • Loading branch information
bors committed May 14, 2020
2 parents 7c34d8d + 56986be commit af6d886
Show file tree
Hide file tree
Showing 72 changed files with 228 additions and 239 deletions.
9 changes: 6 additions & 3 deletions src/bootstrap/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,13 +180,16 @@ def format_build_time(duration):
def default_build_triple():
"""Build triple as in LLVM"""
default_encoding = sys.getdefaultencoding()
required = not sys.platform == 'win32'
ostype = require(["uname", "-s"], exit=required).decode(default_encoding)
cputype = require(['uname', '-m'], exit=required).decode(default_encoding)
required = sys.platform != 'win32'
ostype = require(["uname", "-s"], exit=required)
cputype = require(['uname', '-m'], exit=required)

if ostype is None or cputype is None:
return 'x86_64-pc-windows-msvc'

ostype = ostype.decode(default_encoding)
cputype = cputype.decode(default_encoding)

# The goal here is to come up with the same triple as LLVM would,
# at least for the subset of platforms we're willing to target.
ostype_mapper = {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/book
2 changes: 1 addition & 1 deletion src/doc/edition-guide
2 changes: 1 addition & 1 deletion src/doc/nomicon
2 changes: 1 addition & 1 deletion src/doc/reference
2 changes: 1 addition & 1 deletion src/doc/rust-by-example
8 changes: 5 additions & 3 deletions src/liballoc/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,12 +835,14 @@ impl<T: ?Sized> Arc<T> {
///
/// unsafe {
/// let ptr = Arc::into_raw(five);
/// Arc::decr_strong_count(ptr);
/// Arc::incr_strong_count(ptr);
///
/// // This assertion is deterministic because we haven't shared
/// // Those assertions are deterministic because we haven't shared
/// // the `Arc` between threads.
/// let five = Arc::from_raw(ptr);
/// assert_eq!(0, Arc::strong_count(&five));
/// assert_eq!(2, Arc::strong_count(&five));
/// Arc::decr_strong_count(ptr);
/// assert_eq!(1, Arc::strong_count(&five));
/// }
/// ```
#[inline]
Expand Down
16 changes: 9 additions & 7 deletions src/libcore/any.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,14 +446,16 @@ impl TypeId {
/// # Note
///
/// This is intended for diagnostic use. The exact contents and format of the
/// string are not specified, other than being a best-effort description of the
/// type. For example, `type_name::<Option<String>>()` could return the
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
/// `"foobar"`. In addition, the output may change between versions of the
/// compiler.
/// string returned are not specified, other than being a best-effort
/// description of the type. For example, amongst the strings
/// that `type_name::<Option<String>>()` might return are `"Option<String>"` and
/// `"std::option::Option<std::string::String>"`.
///
/// The type name should not be considered a unique identifier of a type;
/// multiple types may share the same type name.
/// The returned string must not be considered to be a unique identifier of a
/// type as multiple types may map to the same type name. Similarly, there is no
/// guarantee that all parts of a type will appear in the returned string: for
/// example, lifetime specifiers are currently not included. In addition, the
/// output may change between versions of the compiler.
///
/// The current implementation uses the same infrastructure as compiler
/// diagnostics and debuginfo, but this is not guaranteed.
Expand Down
45 changes: 45 additions & 0 deletions src/libcore/option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,20 +1357,65 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {

#[stable(since = "1.12.0", feature = "option_from")]
impl<T> From<T> for Option<T> {
/// Copies `val` into a new `Some`.
///
/// # Examples
///
/// ```
/// let o: Option<u8> = Option::from(67);
///
/// assert_eq!(Some(67), o);
/// ```
fn from(val: T) -> Option<T> {
Some(val)
}
}

#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
/// Converts from `&Option<T>` to `Option<&T>`.
///
/// # Examples
///
/// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original.
/// The [`map`] method takes the `self` argument by value, consuming the original,
/// so this technique uses `as_ref` to first take an `Option` to a reference
/// to the value inside the original.
///
/// [`map`]: ../../std/option/enum.Option.html#method.map
/// [`String`]: ../../std/string/struct.String.html
/// [`usize`]: ../../std/primitive.usize.html
///
/// ```
/// let s: Option<String> = Some(String::from("Hello, Rustaceans!"));
/// let o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len());
///
/// println!("Can still print s: {:?}", s);
///
/// assert_eq!(o, Some(18));
/// ```
fn from(o: &'a Option<T>) -> Option<&'a T> {
o.as_ref()
}
}

#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
/// Converts from `&mut Option<T>` to `Option<&mut T>`
///
/// # Examples
///
/// ```
/// let mut s = Some(String::from("Hello"));
/// let o: Option<&mut String> = Option::from(&mut s);
///
/// match o {
/// Some(t) => *t = String::from("Hello, Rustaceans!"),
/// None => (),
/// }
///
/// assert_eq!(s, Some(String::from("Hello, Rustaceans!")));
/// ```
fn from(o: &'a mut Option<T>) -> Option<&'a mut T> {
o.as_mut()
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_codegen_ssa/debuginfo/type_names.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ pub fn push_debuginfo_type_name<'tcx>(
ty::Error
| ty::Infer(_)
| ty::Placeholder(..)
| ty::UnnormalizedProjection(..)
| ty::Projection(..)
| ty::Bound(..)
| ty::Opaque(..)
Expand Down
9 changes: 6 additions & 3 deletions src/librustc_error_codes/error_codes/E0581.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In a `fn` type, a lifetime appears only in the return type,
In a `fn` type, a lifetime appears only in the return type
and not in the arguments types.

Erroneous code example:
Expand All @@ -10,8 +10,11 @@ fn main() {
}
```

To fix this issue, either use the lifetime in the arguments, or use
`'static`. Example:
The problem here is that the lifetime isn't contrained by any of the arguments,
making it impossible to determine how long it's supposed to live.

To fix this issue, either use the lifetime in the arguments, or use the
`'static` lifetime. Example:

```
fn main() {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_error_codes/error_codes/E0582.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
A lifetime appears only in an associated-type binding,
and not in the input types to the trait.
A lifetime is only present in an associated-type binding, and not in the input
types to the trait.

Erroneous code example:

Expand Down
1 change: 0 additions & 1 deletion src/librustc_infer/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
| ty::Never
| ty::Tuple(..)
| ty::Projection(..)
| ty::UnnormalizedProjection(..)
| ty::Foreign(..)
| ty::Param(..)
| ty::Opaque(..) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_infer/infer/error_reporting/need_type_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
let output = bound_output.skip_binder();
err.span_label(e.span, &format!("this method call resolves to `{:?}`", output));
let kind = &output.kind;
if let ty::Projection(proj) | ty::UnnormalizedProjection(proj) = kind {
if let ty::Projection(proj) = kind {
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
err.span_label(span, &format!("`{:?}` defined here", output));
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_infer/infer/freshen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
| ty::Never
| ty::Tuple(..)
| ty::Projection(..)
| ty::UnnormalizedProjection(..)
| ty::Foreign(..)
| ty::Param(..)
| ty::Closure(..)
Expand Down
1 change: 0 additions & 1 deletion src/librustc_lint/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
| ty::Generator(..)
| ty::GeneratorWitness(..)
| ty::Placeholder(..)
| ty::UnnormalizedProjection(..)
| ty::Projection(..)
| ty::Opaque(..)
| ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty),
Expand Down
28 changes: 18 additions & 10 deletions src/librustc_middle/mir/interpret/pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,27 +89,35 @@ pub struct Pointer<Tag = ()> {

static_assert_size!(Pointer, 16);

/// Print the address of a pointer (without the tag)
fn print_ptr_addr<Tag>(ptr: &Pointer<Tag>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
// Forward `alternate` flag to `alloc_id` printing.
if f.alternate() {
write!(f, "{:#?}", ptr.alloc_id)?;
} else {
write!(f, "{:?}", ptr.alloc_id)?;
}
// Print offset only if it is non-zero.
if ptr.offset.bytes() > 0 {
write!(f, "+0x{:x}", ptr.offset.bytes())?;
}
Ok(())
}

// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
// all the Miri types.
// We have to use `Debug` output for the tag, because `()` does not implement
// `Display` so we cannot specialize that.
impl<Tag: fmt::Debug> fmt::Debug for Pointer<Tag> {
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
} else {
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
}
print_ptr_addr(self, f)?;
write!(f, "[{:?}]", self.tag)
}
}
// Specialization for no tag
impl fmt::Debug for Pointer<()> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if f.alternate() {
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
} else {
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
}
print_ptr_addr(self, f)
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/librustc_middle/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ pub struct CodegenUnit<'tcx> {
size_estimate: Option<usize>,
}

/// Specifies the linkage type for a `MonoItem`.
///
/// See https://llvm.org/docs/LangRef.html#linkage-types for more details about these variants.
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
pub enum Linkage {
External,
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_middle/traits/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,6 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
| ty::Infer(_)
| ty::Bound(..)
| ty::Generator(..) => false,

ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
}
}

Expand Down
1 change: 0 additions & 1 deletion src/librustc_middle/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,6 @@ impl<'tcx> TyCtxt<'tcx> {
Bound,
Param,
Infer,
UnnormalizedProjection,
Projection,
Opaque,
Foreign
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_middle/ty/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
ty::Projection(_) => "associated type".into(),
ty::UnnormalizedProjection(_) => "non-normalized associated type".into(),
ty::Param(p) => format!("type parameter `{}`", p).into(),
ty::Opaque(..) => "opaque type".into(),
ty::Error => "type error".into(),
Expand Down Expand Up @@ -323,7 +322,6 @@ impl<'tcx> ty::TyS<'tcx> {
ty::Placeholder(..) => "higher-ranked type".into(),
ty::Bound(..) => "bound type variable".into(),
ty::Projection(_) => "associated type".into(),
ty::UnnormalizedProjection(_) => "associated type".into(),
ty::Param(_) => "type parameter".into(),
ty::Opaque(..) => "opaque type".into(),
}
Expand Down
1 change: 0 additions & 1 deletion src/librustc_middle/ty/fast_reject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ pub fn simplify_type(
ty::Never => Some(NeverSimplifiedType),
ty::Tuple(ref tys) => Some(TupleSimplifiedType(tys.len())),
ty::FnPtr(ref f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
ty::Projection(_) | ty::Param(_) => {
if can_simplify_params {
// In normalized types, projections don't unify with
Expand Down
5 changes: 0 additions & 5 deletions src/librustc_middle/ty/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,11 +121,6 @@ impl FlagComputation {
self.add_projection_ty(data);
}

&ty::UnnormalizedProjection(ref data) => {
self.add_flags(TypeFlags::HAS_TY_PROJECTION);
self.add_projection_ty(data);
}

&ty::Opaque(_, substs) => {
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
self.add_substs(substs);
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_middle/ty/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,11 +1241,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
tcx.layout_raw(param_env.and(normalized))?
}

ty::Bound(..)
| ty::Placeholder(..)
| ty::UnnormalizedProjection(..)
| ty::GeneratorWitness(..)
| ty::Infer(_) => bug!("Layout::compute: unexpected type `{}`", ty),
ty::Bound(..) | ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
bug!("Layout::compute: unexpected type `{}`", ty)
}

ty::Param(_) | ty::Error => {
return Err(LayoutError::Unknown(ty));
Expand Down Expand Up @@ -2138,7 +2136,6 @@ where
}

ty::Projection(_)
| ty::UnnormalizedProjection(..)
| ty::Bound(..)
| ty::Placeholder(..)
| ty::Opaque(..)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_middle/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ bitflags! {
| TypeFlags::HAS_CT_PLACEHOLDER.bits
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;

/// Does this have [Projection] or [UnnormalizedProjection]?
/// Does this have [Projection]?
const HAS_TY_PROJECTION = 1 << 10;
/// Does this have [Opaque]?
const HAS_TY_OPAQUE = 1 << 11;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_middle/ty/outlives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
}
}

ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),

// We assume that inference variables are fully resolved.
// So, if we encounter an inference variable, just record
// the unresolved variable as a component.
Expand Down
1 change: 0 additions & 1 deletion src/librustc_middle/ty/print/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,6 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
| ty::FnPtr(_)
| ty::Projection(_)
| ty::Placeholder(..)
| ty::UnnormalizedProjection(..)
| ty::Param(_)
| ty::Opaque(..)
| ty::Infer(_)
Expand Down
1 change: 0 additions & 1 deletion src/librustc_middle/ty/print/obsolete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,6 @@ impl DefPathBasedNames<'tcx> {
| ty::Bound(..)
| ty::Infer(_)
| ty::Placeholder(..)
| ty::UnnormalizedProjection(..)
| ty::Projection(..)
| ty::Param(_)
| ty::GeneratorWitness(_)
Expand Down
3 changes: 0 additions & 3 deletions src/librustc_middle/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -540,9 +540,6 @@ pub trait PrettyPrinter<'tcx>:
p!(print_def_path(def_id, &[]));
}
ty::Projection(ref data) => p!(print(data)),
ty::UnnormalizedProjection(ref data) => {
p!(write("Unnormalized("), print(data), write(")"))
}
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
ty::Opaque(def_id, substs) => {
// FIXME(eddyb) print this with `print_def_path`.
Expand Down
Loading

0 comments on commit af6d886

Please sign in to comment.