Skip to content

Commit 9081929

Browse files
committed
Auto merge of #66879 - RalfJung:rollup-nprxpzi, r=RalfJung
Rollup of 11 pull requests Successful merges: - #66379 (Rephrase docs in for ptr) - #66589 (Draw vertical lines correctly in compiler error messages) - #66613 (Allow customising ty::TraitRef's printing behavior) - #66766 (Panic machinery comments and tweaks) - #66791 (Handle GlobalCtxt directly from librustc_interface query system) - #66793 (Record temporary static references in generator witnesses) - #66808 (Cleanup error code) - #66826 (Clarifies how to tag users for assigning PRs) - #66837 (Clarify `{f32,f64}::EPSILON` docs) - #66844 (Miri: do not consider memory allocated by caller_location leaked) - #66872 (Minor documentation fix) Failed merges: r? @ghost
2 parents 25d8a94 + 0b1b36c commit 9081929

File tree

50 files changed

+622
-379
lines changed

Some content is hidden

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

50 files changed

+622
-379
lines changed

CONTRIBUTING.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,13 @@ All pull requests are reviewed by another person. We have a bot,
150150
request.
151151

152152
If you want to request that a specific person reviews your pull request,
153-
you can add an `r?` to the message. For example, [Steve][steveklabnik] usually reviews
153+
you can add an `r?` to the pull request description. For example, [Steve][steveklabnik] usually reviews
154154
documentation changes. So if you were to make a documentation change, add
155155

156156
r? @steveklabnik
157157

158-
to the end of the message, and @rust-highfive will assign [@steveklabnik][steveklabnik] instead
159-
of a random person. This is entirely optional.
158+
to the end of the pull request description, and [@rust-highfive][rust-highfive] will assign
159+
[@steveklabnik][steveklabnik] instead of a random person. This is entirely optional.
160160

161161
After someone has reviewed your pull request, they will leave an annotation
162162
on the pull request with an `r+`. It will look something like this:

src/libcore/any.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ use crate::intrinsics;
6868
// Any trait
6969
///////////////////////////////////////////////////////////////////////////////
7070

71-
/// A type to emulate dynamic typing.
71+
/// A trait to emulate dynamic typing.
7272
///
7373
/// Most types implement `Any`. However, any type which contains a non-`'static` reference does not.
7474
/// See the [module-level documentation][mod] for more details.

src/libcore/num/f32.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub const DIGITS: u32 = 6;
2626

2727
/// [Machine epsilon] value for `f32`.
2828
///
29-
/// This is the difference between `1.0` and the next largest representable number.
29+
/// This is the difference between `1.0` and the next larger representable number.
3030
///
3131
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3232
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/num/f64.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub const DIGITS: u32 = 15;
2626

2727
/// [Machine epsilon] value for `f64`.
2828
///
29-
/// This is the difference between `1.0` and the next largest representable number.
29+
/// This is the difference between `1.0` and the next larger representable number.
3030
///
3131
/// [Machine epsilon]: https://en.wikipedia.org/wiki/Machine_epsilon
3232
#[stable(feature = "rust1", since = "1.0.0")]

src/libcore/panic.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,16 @@ impl fmt::Display for Location<'_> {
266266
#[unstable(feature = "std_internals", issue = "0")]
267267
#[doc(hidden)]
268268
pub unsafe trait BoxMeUp {
269-
fn box_me_up(&mut self) -> *mut (dyn Any + Send);
269+
/// Take full ownership of the contents.
270+
/// The return type is actually `Box<dyn Any + Send>`, but we cannot use `Box` in libcore.
271+
///
272+
/// After this method got called, only some dummy default value is left in `self`.
273+
/// Calling this method twice, or calling `get` after calling this method, is an error.
274+
///
275+
/// The argument is borrowed because the panic runtime (`__rust_start_panic`) only
276+
/// gets a borrowed `dyn BoxMeUp`.
277+
fn take_box(&mut self) -> *mut (dyn Any + Send);
278+
279+
/// Just borrow the contents.
270280
fn get(&mut self) -> &(dyn Any + Send);
271281
}

src/libcore/panicking.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
//! ```
1212
//!
1313
//! This definition allows for panicking with any general message, but it does not
14-
//! allow for failing with a `Box<Any>` value. The reason for this is that libcore
15-
//! is not allowed to allocate.
14+
//! allow for failing with a `Box<Any>` value. (`PanicInfo` just contains a `&(dyn Any + Send)`,
15+
//! for which we fill in a dummy value in `PanicInfo::internal_constructor`.)
16+
//! The reason for this is that libcore is not allowed to allocate.
1617
//!
1718
//! This module contains a few other panicking functions, but these are just the
1819
//! necessary lang items for the compiler. All panics are funneled through this
19-
//! one function. Currently, the actual symbol is declared in the standard
20-
//! library, but the location of this may change over time.
20+
//! one function. The actual symbol is declared through the `#[panic_handler]` attribute.
2121
2222
// ignore-tidy-undocumented-unsafe
2323

@@ -72,6 +72,7 @@ pub fn panic_fmt(fmt: fmt::Arguments<'_>, location: &Location<'_>) -> ! {
7272
}
7373

7474
// NOTE This function never crosses the FFI boundary; it's a Rust-to-Rust call
75+
// that gets resolved to the `#[panic_handler]` function.
7576
extern "Rust" {
7677
#[lang = "panic_impl"]
7778
fn panic_impl(pi: &PanicInfo<'_>) -> !;

src/libcore/ptr/mod.rs

+24-14
Original file line numberDiff line numberDiff line change
@@ -1074,17 +1074,22 @@ impl<T: ?Sized> *const T {
10741074
/// operation because the returned value could be pointing to invalid
10751075
/// memory.
10761076
///
1077-
/// When calling this method, you have to ensure that if the pointer is
1078-
/// non-NULL, then it is properly aligned, dereferencable (for the whole
1079-
/// size of `T`) and points to an initialized instance of `T`. This applies
1080-
/// even if the result of this method is unused!
1077+
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
1078+
/// all of the following is true:
1079+
/// - it is properly aligned
1080+
/// - it must point to an initialized instance of T; in particular, the pointer must be
1081+
/// "dereferencable" in the sense defined [here].
1082+
///
1083+
/// This applies even if the result of this method is unused!
10811084
/// (The part about being initialized is not yet fully decided, but until
10821085
/// it is, the only safe approach is to ensure that they are indeed initialized.)
10831086
///
10841087
/// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
1085-
/// not necessarily reflect the actual lifetime of the data. It is up to the
1086-
/// caller to ensure that for the duration of this lifetime, the memory this
1087-
/// pointer points to does not get written to outside of `UnsafeCell<U>`.
1088+
/// not necessarily reflect the actual lifetime of the data. *You* must enforce
1089+
/// Rust's aliasing rules. In particular, for the duration of this lifetime,
1090+
/// the memory the pointer points to must not get mutated (except inside `UnsafeCell`).
1091+
///
1092+
/// [here]: crate::ptr#safety
10881093
///
10891094
/// # Examples
10901095
///
@@ -1929,18 +1934,23 @@ impl<T: ?Sized> *mut T {
19291934
/// of the returned pointer, nor can it ensure that the lifetime `'a`
19301935
/// returned is indeed a valid lifetime for the contained data.
19311936
///
1932-
/// When calling this method, you have to ensure that if the pointer is
1933-
/// non-NULL, then it is properly aligned, dereferencable (for the whole
1934-
/// size of `T`) and points to an initialized instance of `T`. This applies
1935-
/// even if the result of this method is unused!
1937+
/// When calling this method, you have to ensure that *either* the pointer is NULL *or*
1938+
/// all of the following is true:
1939+
/// - it is properly aligned
1940+
/// - it must point to an initialized instance of T; in particular, the pointer must be
1941+
/// "dereferencable" in the sense defined [here].
1942+
///
1943+
/// This applies even if the result of this method is unused!
19361944
/// (The part about being initialized is not yet fully decided, but until
19371945
/// it is the only safe approach is to ensure that they are indeed initialized.)
19381946
///
19391947
/// Additionally, the lifetime `'a` returned is arbitrarily chosen and does
1940-
/// not necessarily reflect the actual lifetime of the data. It is up to the
1941-
/// caller to ensure that for the duration of this lifetime, the memory this
1942-
/// pointer points to does not get accessed through any other pointer.
1948+
/// not necessarily reflect the actual lifetime of the data. *You* must enforce
1949+
/// Rust's aliasing rules. In particular, for the duration of this lifetime,
1950+
/// the memory this pointer points to must not get accessed (read or written)
1951+
/// through any other pointer.
19431952
///
1953+
/// [here]: crate::ptr#safety
19441954
/// [`as_ref`]: #method.as_ref
19451955
///
19461956
/// # Examples

src/libpanic_unwind/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,5 @@ pub unsafe extern "C" fn __rust_maybe_catch_panic(f: fn(*mut u8),
9494
#[unwind(allowed)]
9595
pub unsafe extern "C" fn __rust_start_panic(payload: usize) -> u32 {
9696
let payload = payload as *mut &mut dyn BoxMeUp;
97-
imp::panic(Box::from_raw((*payload).box_me_up()))
97+
imp::panic(Box::from_raw((*payload).take_box()))
9898
}

src/librustc/arena.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ macro_rules! arena_types {
9393
rustc::hir::def_id::CrateNum
9494
>
9595
>,
96+
[few] hir_forest: rustc::hir::map::Forest,
9697
[few] diagnostic_items: rustc_data_structures::fx::FxHashMap<
9798
syntax::symbol::Symbol,
9899
rustc::hir::def_id::DefId,

src/librustc/hir/map/mod.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub struct Map<'hir> {
200200

201201
map: HirEntryMap<'hir>,
202202

203-
definitions: &'hir Definitions,
203+
definitions: Definitions,
204204

205205
/// The reverse mapping of `node_to_hir_id`.
206206
hir_to_node_id: FxHashMap<HirId, NodeId>,
@@ -267,8 +267,8 @@ impl<'hir> Map<'hir> {
267267
}
268268

269269
#[inline]
270-
pub fn definitions(&self) -> &'hir Definitions {
271-
self.definitions
270+
pub fn definitions(&self) -> &Definitions {
271+
&self.definitions
272272
}
273273

274274
pub fn def_key(&self, def_id: DefId) -> DefKey {
@@ -1251,7 +1251,7 @@ impl Named for ImplItem { fn name(&self) -> Name { self.ident.name } }
12511251
pub fn map_crate<'hir>(sess: &crate::session::Session,
12521252
cstore: &CrateStoreDyn,
12531253
forest: &'hir Forest,
1254-
definitions: &'hir Definitions)
1254+
definitions: Definitions)
12551255
-> Map<'hir> {
12561256
let _prof_timer = sess.prof.generic_activity("build_hir_map");
12571257

@@ -1260,7 +1260,7 @@ pub fn map_crate<'hir>(sess: &crate::session::Session,
12601260
.map(|(node_id, &hir_id)| (hir_id, node_id)).collect();
12611261

12621262
let (map, crate_hash) = {
1263-
let hcx = crate::ich::StableHashingContext::new(sess, &forest.krate, definitions, cstore);
1263+
let hcx = crate::ich::StableHashingContext::new(sess, &forest.krate, &definitions, cstore);
12641264

12651265
let mut collector = NodeCollector::root(sess,
12661266
&forest.krate,

src/librustc/infer/error_reporting/mod.rs

+14-2
Original file line numberDiff line numberDiff line change
@@ -1545,8 +1545,20 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15451545
infer::Types(ref exp_found) => self.expected_found_str_ty(exp_found),
15461546
infer::Regions(ref exp_found) => self.expected_found_str(exp_found),
15471547
infer::Consts(ref exp_found) => self.expected_found_str(exp_found),
1548-
infer::TraitRefs(ref exp_found) => self.expected_found_str(exp_found),
1549-
infer::PolyTraitRefs(ref exp_found) => self.expected_found_str(exp_found),
1548+
infer::TraitRefs(ref exp_found) => {
1549+
let pretty_exp_found = ty::error::ExpectedFound {
1550+
expected: exp_found.expected.print_only_trait_path(),
1551+
found: exp_found.found.print_only_trait_path()
1552+
};
1553+
self.expected_found_str(&pretty_exp_found)
1554+
},
1555+
infer::PolyTraitRefs(ref exp_found) => {
1556+
let pretty_exp_found = ty::error::ExpectedFound {
1557+
expected: exp_found.expected.print_only_trait_path(),
1558+
found: exp_found.found.print_only_trait_path()
1559+
};
1560+
self.expected_found_str(&pretty_exp_found)
1561+
},
15501562
}
15511563
}
15521564

src/librustc/infer/error_reporting/nice_region_error/placeholder_error.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,15 @@ impl NiceRegionError<'me, 'tcx> {
401401
format!(
402402
"{}`{}` would have to be implemented for the type `{}`",
403403
if leading_ellipsis { "..." } else { "" },
404-
expected_trait_ref,
404+
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
405405
expected_trait_ref.map(|tr| tr.self_ty()),
406406
)
407407
} else {
408408
format!(
409409
"{}`{}` must implement `{}`",
410410
if leading_ellipsis { "..." } else { "" },
411411
expected_trait_ref.map(|tr| tr.self_ty()),
412-
expected_trait_ref,
412+
expected_trait_ref.map(|tr| tr.print_only_trait_path()),
413413
)
414414
};
415415

@@ -449,14 +449,14 @@ impl NiceRegionError<'me, 'tcx> {
449449
let mut note = if passive_voice {
450450
format!(
451451
"...but `{}` is actually implemented for the type `{}`",
452-
actual_trait_ref,
452+
actual_trait_ref.map(|tr| tr.print_only_trait_path()),
453453
actual_trait_ref.map(|tr| tr.self_ty()),
454454
)
455455
} else {
456456
format!(
457457
"...but `{}` actually implements `{}`",
458458
actual_trait_ref.map(|tr| tr.self_ty()),
459-
actual_trait_ref,
459+
actual_trait_ref.map(|tr| tr.print_only_trait_path()),
460460
)
461461
};
462462

src/librustc/infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1292,7 +1292,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
12921292
}
12931293

12941294
pub fn trait_ref_to_string(&self, t: &ty::TraitRef<'tcx>) -> String {
1295-
self.resolve_vars_if_possible(t).to_string()
1295+
self.resolve_vars_if_possible(t).print_only_trait_path().to_string()
12961296
}
12971297

12981298
/// If `TyVar(vid)` resolves to a type, return that type. Else, return the

src/librustc/lint/context.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -800,8 +800,13 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> {
800800
// This shouldn't ever be needed, but just in case:
801801
path.push(match trait_ref {
802802
Some(trait_ref) => {
803-
Symbol::intern(&format!("<impl {} for {}>", trait_ref,
804-
self_ty))
803+
Symbol::intern(
804+
&format!(
805+
"<impl {} for {}>",
806+
trait_ref.print_only_trait_path(),
807+
self_ty
808+
)
809+
)
805810
},
806811
None => Symbol::intern(&format!("<impl {}>", self_ty)),
807812
});

src/librustc/traits/error_reporting.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
737737
let is_try = self.tcx.sess.source_map().span_to_snippet(span)
738738
.map(|s| &s == "?")
739739
.unwrap_or(false);
740-
let is_from = format!("{}", trait_ref).starts_with("std::convert::From<");
740+
let is_from =
741+
format!("{}", trait_ref.print_only_trait_path())
742+
.starts_with("std::convert::From<");
741743
let (message, note) = if is_try && is_from {
742744
(Some(format!(
743745
"`?` couldn't convert the error to `{}`",
@@ -768,7 +770,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
768770
format!(
769771
"{}the trait `{}` is not implemented for `{}`",
770772
pre_message,
771-
trait_ref,
773+
trait_ref.print_only_trait_path(),
772774
trait_ref.self_ty(),
773775
)
774776
};
@@ -1189,7 +1191,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11891191
if param_ty => {
11901192
// Missing generic type parameter bound.
11911193
let param_name = self_ty.to_string();
1192-
let constraint = trait_ref.to_string();
1194+
let constraint = trait_ref.print_only_trait_path().to_string();
11931195
if suggest_constraining_type_param(
11941196
generics,
11951197
&mut err,
@@ -1416,7 +1418,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14161418
let msg = format!(
14171419
"the trait bound `{}: {}` is not satisfied",
14181420
found,
1419-
obligation.parent_trait_ref.skip_binder(),
1421+
obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
14201422
);
14211423
if has_custom_message {
14221424
err.note(&msg);
@@ -1430,7 +1432,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14301432
}
14311433
err.span_label(span, &format!(
14321434
"expected an implementor of trait `{}`",
1433-
obligation.parent_trait_ref.skip_binder(),
1435+
obligation.parent_trait_ref.skip_binder().print_only_trait_path(),
14341436
));
14351437
err.span_suggestion(
14361438
span,
@@ -1562,7 +1564,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
15621564
} else {
15631565
err.note(&format!(
15641566
"`{}` is implemented for `{:?}`, but not for `{:?}`",
1565-
trait_ref,
1567+
trait_ref.print_only_trait_path(),
15661568
trait_type,
15671569
trait_ref.skip_binder().self_ty(),
15681570
));
@@ -2226,7 +2228,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22262228

22272229
err.span_note(span, &format!(
22282230
"future does not implement `{}` as this value is used across an await",
2229-
trait_ref,
2231+
trait_ref.print_only_trait_path(),
22302232
));
22312233

22322234
// Add a note for the item obligation that remains - normally a note pointing to the
@@ -2409,7 +2411,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
24092411
let parent_trait_ref = self.resolve_vars_if_possible(&data.parent_trait_ref);
24102412
err.note(
24112413
&format!("required because of the requirements on the impl of `{}` for `{}`",
2412-
parent_trait_ref,
2414+
parent_trait_ref.print_only_trait_path(),
24132415
parent_trait_ref.skip_binder().self_ty()));
24142416
let parent_predicate = parent_trait_ref.to_predicate();
24152417
self.note_obligation_cause_code(err,

src/librustc/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
10441044
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
10451045
let self_ty = trait_ref.self_ty();
10461046
let cause = IntercrateAmbiguityCause::DownstreamCrate {
1047-
trait_desc: trait_ref.to_string(),
1047+
trait_desc: trait_ref.print_only_trait_path().to_string(),
10481048
self_desc: if self_ty.has_concrete_skeleton() {
10491049
Some(self_ty.to_string())
10501050
} else {
@@ -1386,7 +1386,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13861386
if !candidate_set.ambiguous && no_candidates_apply {
13871387
let trait_ref = stack.obligation.predicate.skip_binder().trait_ref;
13881388
let self_ty = trait_ref.self_ty();
1389-
let trait_desc = trait_ref.to_string();
1389+
let trait_desc = trait_ref.print_only_trait_path().to_string();
13901390
let self_desc = if self_ty.has_concrete_skeleton() {
13911391
Some(self_ty.to_string())
13921392
} else {

src/librustc/traits/specialize/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String>
417417
w.push('>');
418418
}
419419

420-
write!(w, " {} for {}", trait_ref, tcx.type_of(impl_def_id)).unwrap();
420+
write!(w, " {} for {}", trait_ref.print_only_trait_path(), tcx.type_of(impl_def_id)).unwrap();
421421

422422
// The predicates will contain default bounds like `T: Sized`. We need to
423423
// remove these bounds, and add `T: ?Sized` to any untouched type parameters.

src/librustc/traits/specialize/specialization_graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ impl<'tcx> Children {
146146
let self_ty = trait_ref.self_ty();
147147
OverlapError {
148148
with_impl: possible_sibling,
149-
trait_desc: trait_ref.to_string(),
149+
trait_desc: trait_ref.print_only_trait_path().to_string(),
150150
// Only report the `Self` type if it has at least
151151
// some outer concrete shell; otherwise, it's
152152
// not adding much information.

0 commit comments

Comments
 (0)