Skip to content

Commit 1557fb0

Browse files
committed
Auto merge of #73643 - Manishearth:rollup-68dr8fz, r=Manishearth
Rollup of 9 pull requests Successful merges: - #72271 (Improve compiler error message for wrong generic parameter order) - #72493 ( move leak-check to during coherence, candidate eval) - #73398 (A way forward for pointer equality in const eval) - #73472 (Clean up E0689 explanation) - #73496 (Account for multiple impl/dyn Trait in return type when suggesting `'_`) - #73515 (Add second message for LiveDrop errors) - #73567 (Clarify --extern documentation.) - #73572 (Fix typos in doc comments) - #73590 (bootstrap: no `config.toml` exists regression) Failed merges: r? @ghost
2 parents 3b1c08c + 44900f8 commit 1557fb0

File tree

206 files changed

+3091
-1578
lines changed

Some content is hidden

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

206 files changed

+3091
-1578
lines changed

src/bootstrap/bootstrap.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,18 @@ def bootstrap(help_triggered):
893893
build.verbose = args.verbose
894894
build.clean = args.clean
895895

896-
try:
897-
toml_path = os.getenv('RUST_BOOTSTRAP_CONFIG') or args.config or 'config.toml'
896+
# Read from `RUST_BOOTSTRAP_CONFIG`, then `--config`, then fallback to `config.toml` (if it
897+
# exists).
898+
toml_path = os.getenv('RUST_BOOTSTRAP_CONFIG') or args.config
899+
if not toml_path and os.path.exists('config.toml'):
900+
toml_path = 'config.toml'
901+
902+
if toml_path:
898903
if not os.path.exists(toml_path):
899904
toml_path = os.path.join(build.rust_root, toml_path)
900905

901906
with open(toml_path) as config:
902907
build.config_toml = config.read()
903-
except (OSError, IOError):
904-
pass
905908

906909
config_verbose = build.get_toml('verbose', 'build')
907910
if config_verbose is not None:
@@ -947,11 +950,12 @@ def bootstrap(help_triggered):
947950
env["SRC"] = build.rust_root
948951
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
949952
env["BOOTSTRAP_PYTHON"] = sys.executable
950-
env["BOOTSTRAP_CONFIG"] = toml_path
951953
env["BUILD_DIR"] = build.build_dir
952954
env["RUSTC_BOOTSTRAP"] = '1'
953955
env["CARGO"] = build.cargo()
954956
env["RUSTC"] = build.rustc()
957+
if toml_path:
958+
env["BOOTSTRAP_CONFIG"] = toml_path
955959
if build.rustfmt():
956960
env["RUSTFMT"] = build.rustfmt()
957961
run(args, env=env, verbose=build.verbose)

src/doc/rustc/src/command-line-arguments.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,18 @@ This flag, when combined with other flags, makes them produce extra output.
273273
This flag allows you to pass the name and location for an external crate of a
274274
direct dependency. Indirect dependencies (dependencies of dependencies) are
275275
located using the [`-L` flag](#option-l-search-path). The given crate name is
276-
added to the [extern prelude], which is the same as specifying `extern crate`
277-
within the root module. The given crate name does not need to match the name
276+
added to the [extern prelude], similar to specifying `extern crate` within the
277+
root module. The given crate name does not need to match the name
278278
the library was built with.
279279

280+
Specifying `--extern` has one behavior difference from `extern crate`:
281+
`--extern` merely makes the crate a _candidate_ for being linked; it does not
282+
actually link it unless it's actively used. In rare occasions you may wish
283+
to ensure a crate is linked even if you don't actively use it from your
284+
code: for example, if it changes the global allocator or if it contains
285+
`#[no_mangle]` symbols for use by other programming languages. In such
286+
cases you'll need to use `extern crate`.
287+
280288
This flag may be specified multiple times. This flag takes an argument with
281289
either of the following formats:
282290

src/liballoc/raw_vec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ impl<T> RawVec<T, Global> {
6060
/// `#[rustc_force_min_const_fn]` attribute which requires conformance
6161
/// with `min_const_fn` but does not necessarily allow calling it in
6262
/// `stable(...) const fn` / user code not enabling `foo` when
63-
/// `#[rustc_const_unstable(feature = "foo", ..)]` is present.
63+
/// `#[rustc_const_unstable(feature = "foo", issue = "01234")]` is present.
6464
pub const NEW: Self = Self::new();
6565

6666
/// Creates the biggest possible `RawVec` (on the system heap)

src/libcore/intrinsics.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ extern "rust-intrinsic" {
10121012
///
10131013
/// The stabilized version of this intrinsic is
10141014
/// [`std::any::type_name`](../../std/any/fn.type_name.html)
1015-
#[rustc_const_unstable(feature = "const_type_name", issue = "none")]
1015+
#[rustc_const_unstable(feature = "const_type_name", issue = "63084")]
10161016
pub fn type_name<T: ?Sized>() -> &'static str;
10171017

10181018
/// Gets an identifier which is globally unique to the specified type. This
@@ -1021,7 +1021,7 @@ extern "rust-intrinsic" {
10211021
///
10221022
/// The stabilized version of this intrinsic is
10231023
/// [`std::any::TypeId::of`](../../std/any/struct.TypeId.html#method.of)
1024-
#[rustc_const_unstable(feature = "const_type_id", issue = "none")]
1024+
#[rustc_const_unstable(feature = "const_type_id", issue = "41875")]
10251025
pub fn type_id<T: ?Sized + 'static>() -> u64;
10261026

10271027
/// A guard for unsafe functions that cannot ever be executed if `T` is uninhabited:
@@ -1931,7 +1931,7 @@ extern "rust-intrinsic" {
19311931
pub fn nontemporal_store<T>(ptr: *mut T, val: T);
19321932

19331933
/// See documentation of `<*const T>::offset_from` for details.
1934-
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "none")]
1934+
#[rustc_const_unstable(feature = "const_ptr_offset_from", issue = "41079")]
19351935
pub fn ptr_offset_from<T>(ptr: *const T, base: *const T) -> isize;
19361936

19371937
/// Internal hook used by Miri to implement unwinding.
@@ -1948,6 +1948,16 @@ extern "rust-intrinsic" {
19481948
#[cfg(not(bootstrap))]
19491949
#[lang = "count_code_region"]
19501950
pub fn count_code_region(index: u32);
1951+
1952+
/// See documentation of `<*const T>::guaranteed_eq` for details.
1953+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1954+
#[cfg(not(bootstrap))]
1955+
pub fn ptr_guaranteed_eq<T>(ptr: *const T, other: *const T) -> bool;
1956+
1957+
/// See documentation of `<*const T>::guaranteed_ne` for details.
1958+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
1959+
#[cfg(not(bootstrap))]
1960+
pub fn ptr_guaranteed_ne<T>(ptr: *const T, other: *const T) -> bool;
19511961
}
19521962

19531963
// Some functions are defined here because they accidentally got made

src/libcore/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@
8787
#![feature(const_generics)]
8888
#![feature(const_ptr_offset)]
8989
#![feature(const_ptr_offset_from)]
90+
#![cfg_attr(not(bootstrap), feature(const_raw_ptr_comparison))]
9091
#![feature(const_result)]
9192
#![feature(const_slice_from_raw_parts)]
9293
#![feature(const_slice_ptr_len)]

src/libcore/ptr/const_ptr.rs

+66
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,72 @@ impl<T: ?Sized> *const T {
295295
intrinsics::ptr_offset_from(self, origin)
296296
}
297297

298+
/// Returns whether two pointers are guaranteed to be equal.
299+
///
300+
/// At runtime this function behaves like `self == other`.
301+
/// However, in some contexts (e.g., compile-time evaluation),
302+
/// it is not always possible to determine equality of two pointers, so this function may
303+
/// spuriously return `false` for pointers that later actually turn out to be equal.
304+
/// But when it returns `true`, the pointers are guaranteed to be equal.
305+
///
306+
/// This function is the mirror of [`guaranteed_ne`], but not its inverse. There are pointer
307+
/// comparisons for which both functions return `false`.
308+
///
309+
/// [`guaranteed_ne`]: #method.guaranteed_ne
310+
///
311+
/// The return value may change depending on the compiler version and unsafe code may not
312+
/// rely on the result of this function for soundness. It is suggested to only use this function
313+
/// for performance optimizations where spurious `false` return values by this function do not
314+
/// affect the outcome, but just the performance.
315+
/// The consequences of using this method to make runtime and compile-time code behave
316+
/// differently have not been explored. This method should not be used to introduce such
317+
/// differences, and it should also not be stabilized before we have a better understanding
318+
/// of this issue.
319+
/// ```
320+
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
321+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
322+
#[inline]
323+
#[cfg(not(bootstrap))]
324+
pub const fn guaranteed_eq(self, other: *const T) -> bool
325+
where
326+
T: Sized,
327+
{
328+
intrinsics::ptr_guaranteed_eq(self, other)
329+
}
330+
331+
/// Returns whether two pointers are guaranteed to be inequal.
332+
///
333+
/// At runtime this function behaves like `self != other`.
334+
/// However, in some contexts (e.g., compile-time evaluation),
335+
/// it is not always possible to determine the inequality of two pointers, so this function may
336+
/// spuriously return `false` for pointers that later actually turn out to be inequal.
337+
/// But when it returns `true`, the pointers are guaranteed to be inequal.
338+
///
339+
/// This function is the mirror of [`guaranteed_eq`], but not its inverse. There are pointer
340+
/// comparisons for which both functions return `false`.
341+
///
342+
/// [`guaranteed_eq`]: #method.guaranteed_eq
343+
///
344+
/// The return value may change depending on the compiler version and unsafe code may not
345+
/// rely on the result of this function for soundness. It is suggested to only use this function
346+
/// for performance optimizations where spurious `false` return values by this function do not
347+
/// affect the outcome, but just the performance.
348+
/// The consequences of using this method to make runtime and compile-time code behave
349+
/// differently have not been explored. This method should not be used to introduce such
350+
/// differences, and it should also not be stabilized before we have a better understanding
351+
/// of this issue.
352+
/// ```
353+
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
354+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
355+
#[inline]
356+
#[cfg(not(bootstrap))]
357+
pub const fn guaranteed_ne(self, other: *const T) -> bool
358+
where
359+
T: Sized,
360+
{
361+
intrinsics::ptr_guaranteed_ne(self, other)
362+
}
363+
298364
/// Calculates the distance between two pointers. The returned value is in
299365
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
300366
///

src/libcore/ptr/mut_ptr.rs

+66
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,72 @@ impl<T: ?Sized> *mut T {
273273
if self.is_null() { None } else { Some(&mut *self) }
274274
}
275275

276+
/// Returns whether two pointers are guaranteed to be equal.
277+
///
278+
/// At runtime this function behaves like `self == other`.
279+
/// However, in some contexts (e.g., compile-time evaluation),
280+
/// it is not always possible to determine equality of two pointers, so this function may
281+
/// spuriously return `false` for pointers that later actually turn out to be equal.
282+
/// But when it returns `true`, the pointers are guaranteed to be equal.
283+
///
284+
/// This function is the mirror of [`guaranteed_ne`], but not its inverse. There are pointer
285+
/// comparisons for which both functions return `false`.
286+
///
287+
/// [`guaranteed_ne`]: #method.guaranteed_ne
288+
///
289+
/// The return value may change depending on the compiler version and unsafe code may not
290+
/// rely on the result of this function for soundness. It is suggested to only use this function
291+
/// for performance optimizations where spurious `false` return values by this function do not
292+
/// affect the outcome, but just the performance.
293+
/// The consequences of using this method to make runtime and compile-time code behave
294+
/// differently have not been explored. This method should not be used to introduce such
295+
/// differences, and it should also not be stabilized before we have a better understanding
296+
/// of this issue.
297+
/// ```
298+
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
299+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
300+
#[inline]
301+
#[cfg(not(bootstrap))]
302+
pub const fn guaranteed_eq(self, other: *mut T) -> bool
303+
where
304+
T: Sized,
305+
{
306+
intrinsics::ptr_guaranteed_eq(self as *const _, other as *const _)
307+
}
308+
309+
/// Returns whether two pointers are guaranteed to be inequal.
310+
///
311+
/// At runtime this function behaves like `self != other`.
312+
/// However, in some contexts (e.g., compile-time evaluation),
313+
/// it is not always possible to determine the inequality of two pointers, so this function may
314+
/// spuriously return `false` for pointers that later actually turn out to be inequal.
315+
/// But when it returns `true`, the pointers are guaranteed to be inequal.
316+
///
317+
/// This function is the mirror of [`guaranteed_eq`], but not its inverse. There are pointer
318+
/// comparisons for which both functions return `false`.
319+
///
320+
/// [`guaranteed_eq`]: #method.guaranteed_eq
321+
///
322+
/// The return value may change depending on the compiler version and unsafe code may not
323+
/// rely on the result of this function for soundness. It is suggested to only use this function
324+
/// for performance optimizations where spurious `false` return values by this function do not
325+
/// affect the outcome, but just the performance.
326+
/// The consequences of using this method to make runtime and compile-time code behave
327+
/// differently have not been explored. This method should not be used to introduce such
328+
/// differences, and it should also not be stabilized before we have a better understanding
329+
/// of this issue.
330+
/// ```
331+
#[unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
332+
#[rustc_const_unstable(feature = "const_raw_ptr_comparison", issue = "53020")]
333+
#[inline]
334+
#[cfg(not(bootstrap))]
335+
pub const unsafe fn guaranteed_ne(self, other: *mut T) -> bool
336+
where
337+
T: Sized,
338+
{
339+
intrinsics::ptr_guaranteed_ne(self as *const _, other as *const _)
340+
}
341+
276342
/// Calculates the distance between two pointers. The returned value is in
277343
/// units of T: the distance in bytes is divided by `mem::size_of::<T>()`.
278344
///

src/libcore/slice/mod.rs

+17
Original file line numberDiff line numberDiff line change
@@ -5956,10 +5956,18 @@ where
59565956
return false;
59575957
}
59585958

5959+
#[cfg(bootstrap)]
59595960
if self.as_ptr() == other.as_ptr() {
59605961
return true;
59615962
}
59625963

5964+
// While performance would suffer if `guaranteed_eq` just returned `false`
5965+
// for all arguments, correctness and return value of this function are not affected.
5966+
#[cfg(not(bootstrap))]
5967+
if self.as_ptr().guaranteed_eq(other.as_ptr()) {
5968+
return true;
5969+
}
5970+
59635971
self.iter().zip(other.iter()).all(|(x, y)| x == y)
59645972
}
59655973
}
@@ -5973,9 +5981,18 @@ where
59735981
if self.len() != other.len() {
59745982
return false;
59755983
}
5984+
5985+
#[cfg(bootstrap)]
59765986
if self.as_ptr() == other.as_ptr() {
59775987
return true;
59785988
}
5989+
5990+
// While performance would suffer if `guaranteed_eq` just returned `false`
5991+
// for all arguments, correctness and return value of this function are not affected.
5992+
#[cfg(not(bootstrap))]
5993+
if self.as_ptr().guaranteed_eq(other.as_ptr()) {
5994+
return true;
5995+
}
59795996
unsafe {
59805997
let size = mem::size_of_val(self);
59815998
memcmp(self.as_ptr() as *const u8, other.as_ptr() as *const u8, size) == 0

src/librustc_codegen_llvm/intrinsic.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use log::debug;
1212
use rustc_ast::ast;
1313
use rustc_codegen_ssa::base::{compare_simd_types, to_immediate, wants_msvc_seh};
1414
use rustc_codegen_ssa::common::span_invalid_monomorphization_error;
15-
use rustc_codegen_ssa::common::TypeKind;
15+
use rustc_codegen_ssa::common::{IntPredicate, TypeKind};
1616
use rustc_codegen_ssa::glue;
1717
use rustc_codegen_ssa::mir::operand::{OperandRef, OperandValue};
1818
use rustc_codegen_ssa::mir::place::PlaceRef;
@@ -731,6 +731,16 @@ impl IntrinsicCallMethods<'tcx> for Builder<'a, 'll, 'tcx> {
731731
return;
732732
}
733733

734+
"ptr_guaranteed_eq" | "ptr_guaranteed_ne" => {
735+
let a = args[0].immediate();
736+
let b = args[1].immediate();
737+
if name == "ptr_guaranteed_eq" {
738+
self.icmp(IntPredicate::IntEQ, a, b)
739+
} else {
740+
self.icmp(IntPredicate::IntNE, a, b)
741+
}
742+
}
743+
734744
"ptr_offset_from" => {
735745
let ty = substs.type_at(0);
736746
let pointee_size = self.size_of(ty);
+11-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
This error indicates that the numeric value for the method being passed exists
2-
but the type of the numeric value or binding could not be identified.
1+
A method was called on an ambiguous numeric type.
32

4-
The error happens on numeric literals:
3+
Erroneous code example:
54

65
```compile_fail,E0689
7-
2.0.neg();
6+
2.0.neg(); // error!
87
```
98

10-
and on numeric bindings without an identified concrete type:
9+
This error indicates that the numeric value for the method being passed exists
10+
but the type of the numeric value or binding could not be identified.
11+
12+
The error happens on numeric literals and on numeric bindings without an
13+
identified concrete type:
1114

1215
```compile_fail,E0689
1316
let x = 2.0;
@@ -19,8 +22,8 @@ Because of this, you must give the numeric literal or binding a type:
1922
```
2023
use std::ops::Neg;
2124
22-
let _ = 2.0_f32.neg();
25+
let _ = 2.0_f32.neg(); // ok!
2326
let x: f32 = 2.0;
24-
let _ = x.neg();
25-
let _ = (2.0 as f32).neg();
27+
let _ = x.neg(); // ok!
28+
let _ = (2.0 as f32).neg(); // ok!
2629
```

src/librustc_feature/active.rs

-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,6 @@ declare_features! (
401401
/// Allows dereferencing raw pointers during const eval.
402402
(active, const_raw_ptr_deref, "1.27.0", Some(51911), None),
403403

404-
/// Allows comparing raw pointers during const eval.
405-
(active, const_compare_raw_pointers, "1.27.0", Some(53020), None),
406-
407404
/// Allows `#[doc(alias = "...")]`.
408405
(active, doc_alias, "1.27.0", Some(50146), None),
409406

src/librustc_feature/removed.rs

+5
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ declare_features! (
113113
Some("removed in favor of `#![feature(marker_trait_attr)]`")),
114114
/// Allows `#[no_debug]`.
115115
(removed, no_debug, "1.43.0", Some(29721), None, Some("removed due to lack of demand")),
116+
117+
/// Allows comparing raw pointers during const eval.
118+
(removed, const_compare_raw_pointers, "1.46.0", Some(53020), None,
119+
Some("cannot be allowed in const eval in any meaningful way")),
120+
116121
// -------------------------------------------------------------------------
117122
// feature-group-end: removed features
118123
// -------------------------------------------------------------------------

src/librustc_infer/infer/error_reporting/nice_region_error/find_anon_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2626
&self,
2727
region: Region<'tcx>,
2828
br: &ty::BoundRegion,
29-
) -> Option<(&hir::Ty<'_>, &hir::FnDecl<'_>)> {
29+
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3131
let def_id = anon_reg.def_id;
3232
if let Some(def_id) = def_id.as_local() {

0 commit comments

Comments
 (0)