Skip to content

Commit af6d886

Browse files
committed
Auto merge of #72187 - RalfJung:rollup-a7a9jdi, r=RalfJung
Rollup of 12 pull requests Successful merges: - #71525 (`prefix` should not be mutable.) - #71741 (Pointer printing: do not print 0 offset) - #71870 (Be slightly more precise about any::type_name()'s guarantees.) - #71909 (Document From trait for Option implementations) - #71964 (Fix bootstrap failing on win32) - #72137 (Clean up E0581 explanation) - #72138 (Add doc comment for `rustc_middle::mir::mono::Linkage`) - #72150 (Remove UnnormalizedProjection) - #72151 (Update books) - #72163 (docs: remove comment referencing non-existent method) - #72169 (Clean up E0582 explanation) - #72183 (Fix Arc::decr_strong_count doc test) Failed merges: r? @ghost
2 parents 7c34d8d + 56986be commit af6d886

File tree

72 files changed

+228
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+228
-239
lines changed

src/bootstrap/bootstrap.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -180,13 +180,16 @@ def format_build_time(duration):
180180
def default_build_triple():
181181
"""Build triple as in LLVM"""
182182
default_encoding = sys.getdefaultencoding()
183-
required = not sys.platform == 'win32'
184-
ostype = require(["uname", "-s"], exit=required).decode(default_encoding)
185-
cputype = require(['uname', '-m'], exit=required).decode(default_encoding)
183+
required = sys.platform != 'win32'
184+
ostype = require(["uname", "-s"], exit=required)
185+
cputype = require(['uname', '-m'], exit=required)
186186

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

190+
ostype = ostype.decode(default_encoding)
191+
cputype = cputype.decode(default_encoding)
192+
190193
# The goal here is to come up with the same triple as LLVM would,
191194
# at least for the subset of platforms we're willing to target.
192195
ostype_mapper = {

src/liballoc/sync.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -835,12 +835,14 @@ impl<T: ?Sized> Arc<T> {
835835
///
836836
/// unsafe {
837837
/// let ptr = Arc::into_raw(five);
838-
/// Arc::decr_strong_count(ptr);
838+
/// Arc::incr_strong_count(ptr);
839839
///
840-
/// // This assertion is deterministic because we haven't shared
840+
/// // Those assertions are deterministic because we haven't shared
841841
/// // the `Arc` between threads.
842842
/// let five = Arc::from_raw(ptr);
843-
/// assert_eq!(0, Arc::strong_count(&five));
843+
/// assert_eq!(2, Arc::strong_count(&five));
844+
/// Arc::decr_strong_count(ptr);
845+
/// assert_eq!(1, Arc::strong_count(&five));
844846
/// }
845847
/// ```
846848
#[inline]

src/libcore/any.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -446,14 +446,16 @@ impl TypeId {
446446
/// # Note
447447
///
448448
/// This is intended for diagnostic use. The exact contents and format of the
449-
/// string are not specified, other than being a best-effort description of the
450-
/// type. For example, `type_name::<Option<String>>()` could return the
451-
/// `"Option<String>"` or `"std::option::Option<std::string::String>"`, but not
452-
/// `"foobar"`. In addition, the output may change between versions of the
453-
/// compiler.
449+
/// string returned are not specified, other than being a best-effort
450+
/// description of the type. For example, amongst the strings
451+
/// that `type_name::<Option<String>>()` might return are `"Option<String>"` and
452+
/// `"std::option::Option<std::string::String>"`.
454453
///
455-
/// The type name should not be considered a unique identifier of a type;
456-
/// multiple types may share the same type name.
454+
/// The returned string must not be considered to be a unique identifier of a
455+
/// type as multiple types may map to the same type name. Similarly, there is no
456+
/// guarantee that all parts of a type will appear in the returned string: for
457+
/// example, lifetime specifiers are currently not included. In addition, the
458+
/// output may change between versions of the compiler.
457459
///
458460
/// The current implementation uses the same infrastructure as compiler
459461
/// diagnostics and debuginfo, but this is not guaranteed.

src/libcore/option.rs

+45
Original file line numberDiff line numberDiff line change
@@ -1357,20 +1357,65 @@ impl<'a, T> IntoIterator for &'a mut Option<T> {
13571357

13581358
#[stable(since = "1.12.0", feature = "option_from")]
13591359
impl<T> From<T> for Option<T> {
1360+
/// Copies `val` into a new `Some`.
1361+
///
1362+
/// # Examples
1363+
///
1364+
/// ```
1365+
/// let o: Option<u8> = Option::from(67);
1366+
///
1367+
/// assert_eq!(Some(67), o);
1368+
/// ```
13601369
fn from(val: T) -> Option<T> {
13611370
Some(val)
13621371
}
13631372
}
13641373

13651374
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
13661375
impl<'a, T> From<&'a Option<T>> for Option<&'a T> {
1376+
/// Converts from `&Option<T>` to `Option<&T>`.
1377+
///
1378+
/// # Examples
1379+
///
1380+
/// Converts an `Option<`[`String`]`>` into an `Option<`[`usize`]`>`, preserving the original.
1381+
/// The [`map`] method takes the `self` argument by value, consuming the original,
1382+
/// so this technique uses `as_ref` to first take an `Option` to a reference
1383+
/// to the value inside the original.
1384+
///
1385+
/// [`map`]: ../../std/option/enum.Option.html#method.map
1386+
/// [`String`]: ../../std/string/struct.String.html
1387+
/// [`usize`]: ../../std/primitive.usize.html
1388+
///
1389+
/// ```
1390+
/// let s: Option<String> = Some(String::from("Hello, Rustaceans!"));
1391+
/// let o: Option<usize> = Option::from(&s).map(|ss: &String| ss.len());
1392+
///
1393+
/// println!("Can still print s: {:?}", s);
1394+
///
1395+
/// assert_eq!(o, Some(18));
1396+
/// ```
13671397
fn from(o: &'a Option<T>) -> Option<&'a T> {
13681398
o.as_ref()
13691399
}
13701400
}
13711401

13721402
#[stable(feature = "option_ref_from_ref_option", since = "1.30.0")]
13731403
impl<'a, T> From<&'a mut Option<T>> for Option<&'a mut T> {
1404+
/// Converts from `&mut Option<T>` to `Option<&mut T>`
1405+
///
1406+
/// # Examples
1407+
///
1408+
/// ```
1409+
/// let mut s = Some(String::from("Hello"));
1410+
/// let o: Option<&mut String> = Option::from(&mut s);
1411+
///
1412+
/// match o {
1413+
/// Some(t) => *t = String::from("Hello, Rustaceans!"),
1414+
/// None => (),
1415+
/// }
1416+
///
1417+
/// assert_eq!(s, Some(String::from("Hello, Rustaceans!")));
1418+
/// ```
13741419
fn from(o: &'a mut Option<T>) -> Option<&'a mut T> {
13751420
o.as_mut()
13761421
}

src/librustc_codegen_ssa/debuginfo/type_names.rs

-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ pub fn push_debuginfo_type_name<'tcx>(
198198
ty::Error
199199
| ty::Infer(_)
200200
| ty::Placeholder(..)
201-
| ty::UnnormalizedProjection(..)
202201
| ty::Projection(..)
203202
| ty::Bound(..)
204203
| ty::Opaque(..)

src/librustc_error_codes/error_codes/E0581.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
In a `fn` type, a lifetime appears only in the return type,
1+
In a `fn` type, a lifetime appears only in the return type
22
and not in the arguments types.
33

44
Erroneous code example:
@@ -10,8 +10,11 @@ fn main() {
1010
}
1111
```
1212

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

1619
```
1720
fn main() {

src/librustc_error_codes/error_codes/E0582.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
A lifetime appears only in an associated-type binding,
2-
and not in the input types to the trait.
1+
A lifetime is only present in an associated-type binding, and not in the input
2+
types to the trait.
33

44
Erroneous code example:
55

src/librustc_infer/infer/canonical/canonicalizer.rs

-1
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,6 @@ impl<'cx, 'tcx> TypeFolder<'tcx> for Canonicalizer<'cx, 'tcx> {
415415
| ty::Never
416416
| ty::Tuple(..)
417417
| ty::Projection(..)
418-
| ty::UnnormalizedProjection(..)
419418
| ty::Foreign(..)
420419
| ty::Param(..)
421420
| ty::Opaque(..) => {

src/librustc_infer/infer/error_reporting/need_type_info.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
554554
let output = bound_output.skip_binder();
555555
err.span_label(e.span, &format!("this method call resolves to `{:?}`", output));
556556
let kind = &output.kind;
557-
if let ty::Projection(proj) | ty::UnnormalizedProjection(proj) = kind {
557+
if let ty::Projection(proj) = kind {
558558
if let Some(span) = self.tcx.hir().span_if_local(proj.item_def_id) {
559559
err.span_label(span, &format!("`{:?}` defined here", output));
560560
}

src/librustc_infer/infer/freshen.rs

-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,6 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
204204
| ty::Never
205205
| ty::Tuple(..)
206206
| ty::Projection(..)
207-
| ty::UnnormalizedProjection(..)
208207
| ty::Foreign(..)
209208
| ty::Param(..)
210209
| ty::Closure(..)

src/librustc_lint/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,6 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
888888
| ty::Generator(..)
889889
| ty::GeneratorWitness(..)
890890
| ty::Placeholder(..)
891-
| ty::UnnormalizedProjection(..)
892891
| ty::Projection(..)
893892
| ty::Opaque(..)
894893
| ty::FnDef(..) => bug!("unexpected type in foreign function: {:?}", ty),

src/librustc_middle/mir/interpret/pointer.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -89,27 +89,35 @@ pub struct Pointer<Tag = ()> {
8989

9090
static_assert_size!(Pointer, 16);
9191

92+
/// Print the address of a pointer (without the tag)
93+
fn print_ptr_addr<Tag>(ptr: &Pointer<Tag>, f: &mut fmt::Formatter<'_>) -> fmt::Result {
94+
// Forward `alternate` flag to `alloc_id` printing.
95+
if f.alternate() {
96+
write!(f, "{:#?}", ptr.alloc_id)?;
97+
} else {
98+
write!(f, "{:?}", ptr.alloc_id)?;
99+
}
100+
// Print offset only if it is non-zero.
101+
if ptr.offset.bytes() > 0 {
102+
write!(f, "+0x{:x}", ptr.offset.bytes())?;
103+
}
104+
Ok(())
105+
}
106+
92107
// We want the `Debug` output to be readable as it is used by `derive(Debug)` for
93108
// all the Miri types.
94109
// We have to use `Debug` output for the tag, because `()` does not implement
95110
// `Display` so we cannot specialize that.
96111
impl<Tag: fmt::Debug> fmt::Debug for Pointer<Tag> {
97112
default fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
98-
if f.alternate() {
99-
write!(f, "{:#?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
100-
} else {
101-
write!(f, "{:?}+0x{:x}[{:?}]", self.alloc_id, self.offset.bytes(), self.tag)
102-
}
113+
print_ptr_addr(self, f)?;
114+
write!(f, "[{:?}]", self.tag)
103115
}
104116
}
105117
// Specialization for no tag
106118
impl fmt::Debug for Pointer<()> {
107119
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
108-
if f.alternate() {
109-
write!(f, "{:#?}+0x{:x}", self.alloc_id, self.offset.bytes())
110-
} else {
111-
write!(f, "{:?}+0x{:x}", self.alloc_id, self.offset.bytes())
112-
}
120+
print_ptr_addr(self, f)
113121
}
114122
}
115123

src/librustc_middle/mir/mono.rs

+3
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ pub struct CodegenUnit<'tcx> {
239239
size_estimate: Option<usize>,
240240
}
241241

242+
/// Specifies the linkage type for a `MonoItem`.
243+
///
244+
/// See https://llvm.org/docs/LangRef.html#linkage-types for more details about these variants.
242245
#[derive(Copy, Clone, PartialEq, Debug, RustcEncodable, RustcDecodable, HashStable)]
243246
pub enum Linkage {
244247
External,

src/librustc_middle/traits/query.rs

-2
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,6 @@ pub fn trivial_dropck_outlives<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> bool {
255255
| ty::Infer(_)
256256
| ty::Bound(..)
257257
| ty::Generator(..) => false,
258-
259-
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
260258
}
261259
}
262260

src/librustc_middle/ty/context.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,6 @@ impl<'tcx> TyCtxt<'tcx> {
18781878
Bound,
18791879
Param,
18801880
Infer,
1881-
UnnormalizedProjection,
18821881
Projection,
18831882
Opaque,
18841883
Foreign

src/librustc_middle/ty/error.rs

-2
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ impl<'tcx> ty::TyS<'tcx> {
284284
ty::Infer(ty::FreshIntTy(_)) => "fresh integral type".into(),
285285
ty::Infer(ty::FreshFloatTy(_)) => "fresh floating-point type".into(),
286286
ty::Projection(_) => "associated type".into(),
287-
ty::UnnormalizedProjection(_) => "non-normalized associated type".into(),
288287
ty::Param(p) => format!("type parameter `{}`", p).into(),
289288
ty::Opaque(..) => "opaque type".into(),
290289
ty::Error => "type error".into(),
@@ -323,7 +322,6 @@ impl<'tcx> ty::TyS<'tcx> {
323322
ty::Placeholder(..) => "higher-ranked type".into(),
324323
ty::Bound(..) => "bound type variable".into(),
325324
ty::Projection(_) => "associated type".into(),
326-
ty::UnnormalizedProjection(_) => "associated type".into(),
327325
ty::Param(_) => "type parameter".into(),
328326
ty::Opaque(..) => "opaque type".into(),
329327
}

src/librustc_middle/ty/fast_reject.rs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub fn simplify_type(
9090
ty::Never => Some(NeverSimplifiedType),
9191
ty::Tuple(ref tys) => Some(TupleSimplifiedType(tys.len())),
9292
ty::FnPtr(ref f) => Some(FunctionSimplifiedType(f.skip_binder().inputs().len())),
93-
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
9493
ty::Projection(_) | ty::Param(_) => {
9594
if can_simplify_params {
9695
// In normalized types, projections don't unify with

src/librustc_middle/ty/flags.rs

-5
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,6 @@ impl FlagComputation {
121121
self.add_projection_ty(data);
122122
}
123123

124-
&ty::UnnormalizedProjection(ref data) => {
125-
self.add_flags(TypeFlags::HAS_TY_PROJECTION);
126-
self.add_projection_ty(data);
127-
}
128-
129124
&ty::Opaque(_, substs) => {
130125
self.add_flags(TypeFlags::HAS_TY_OPAQUE);
131126
self.add_substs(substs);

src/librustc_middle/ty/layout.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1241,11 +1241,9 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
12411241
tcx.layout_raw(param_env.and(normalized))?
12421242
}
12431243

1244-
ty::Bound(..)
1245-
| ty::Placeholder(..)
1246-
| ty::UnnormalizedProjection(..)
1247-
| ty::GeneratorWitness(..)
1248-
| ty::Infer(_) => bug!("Layout::compute: unexpected type `{}`", ty),
1244+
ty::Bound(..) | ty::Placeholder(..) | ty::GeneratorWitness(..) | ty::Infer(_) => {
1245+
bug!("Layout::compute: unexpected type `{}`", ty)
1246+
}
12491247

12501248
ty::Param(_) | ty::Error => {
12511249
return Err(LayoutError::Unknown(ty));
@@ -2138,7 +2136,6 @@ where
21382136
}
21392137

21402138
ty::Projection(_)
2141-
| ty::UnnormalizedProjection(..)
21422139
| ty::Bound(..)
21432140
| ty::Placeholder(..)
21442141
| ty::Opaque(..)

src/librustc_middle/ty/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ bitflags! {
555555
| TypeFlags::HAS_CT_PLACEHOLDER.bits
556556
| TypeFlags::HAS_FREE_LOCAL_REGIONS.bits;
557557

558-
/// Does this have [Projection] or [UnnormalizedProjection]?
558+
/// Does this have [Projection]?
559559
const HAS_TY_PROJECTION = 1 << 10;
560560
/// Does this have [Opaque]?
561561
const HAS_TY_OPAQUE = 1 << 11;

src/librustc_middle/ty/outlives.rs

-2
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,6 @@ fn compute_components(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, out: &mut SmallVec<[Compo
135135
}
136136
}
137137

138-
ty::UnnormalizedProjection(..) => bug!("only used with chalk-engine"),
139-
140138
// We assume that inference variables are fully resolved.
141139
// So, if we encounter an inference variable, just record
142140
// the unresolved variable as a component.

src/librustc_middle/ty/print/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ pub fn characteristic_def_id_of_type(ty: Ty<'_>) -> Option<DefId> {
294294
| ty::FnPtr(_)
295295
| ty::Projection(_)
296296
| ty::Placeholder(..)
297-
| ty::UnnormalizedProjection(..)
298297
| ty::Param(_)
299298
| ty::Opaque(..)
300299
| ty::Infer(_)

src/librustc_middle/ty/print/obsolete.rs

-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ impl DefPathBasedNames<'tcx> {
148148
| ty::Bound(..)
149149
| ty::Infer(_)
150150
| ty::Placeholder(..)
151-
| ty::UnnormalizedProjection(..)
152151
| ty::Projection(..)
153152
| ty::Param(_)
154153
| ty::GeneratorWitness(_)

src/librustc_middle/ty/print/pretty.rs

-3
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,6 @@ pub trait PrettyPrinter<'tcx>:
540540
p!(print_def_path(def_id, &[]));
541541
}
542542
ty::Projection(ref data) => p!(print(data)),
543-
ty::UnnormalizedProjection(ref data) => {
544-
p!(write("Unnormalized("), print(data), write(")"))
545-
}
546543
ty::Placeholder(placeholder) => p!(write("Placeholder({:?})", placeholder)),
547544
ty::Opaque(def_id, substs) => {
548545
// FIXME(eddyb) print this with `print_def_path`.

0 commit comments

Comments
 (0)