Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 13 pull requests #89843

Closed
wants to merge 32 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
58b1a12
Avoid allocations and copying in Vec::leak
mbrubeck Sep 28, 2021
1fca2ce
Additional docs about Vec::leak behavior
mbrubeck Sep 28, 2021
e71d17b
Edit explanation of test for nested type ascriptions
pierwill Oct 11, 2021
e56d89a
Add missing words in `Infallible` docs
Wilfred Oct 11, 2021
d2564ce
rustdoc: update noto sans kr
Oct 11, 2021
0cf84c8
Add #[must_use] to to_value conversions
jkugelman Oct 11, 2021
0767ed3
add some more testcases
hellow554 Oct 11, 2021
7943c9c
Use Option::map_or instead of open coding it
LingMan Oct 12, 2021
129af04
Mention Rust version in Vec::leak docs.
m-ou-se Oct 12, 2021
81eeb3e
Fix uppercase/lowercase error
jkugelman Oct 12, 2021
df15b28
Remove potentially unsound note on reconstructing a leaked Vec.
m-ou-se Oct 12, 2021
e5cfe84
Fix invalid rules in .gitignore
Canop Oct 12, 2021
a6bb1fb
Add #[inline] to int log10 functions.
m-ou-se Oct 12, 2021
7a646df
Add missing entries for overflow-checks to config.toml.example.
hkratz Oct 11, 2021
cfc7782
Add --enable-overflow-checks-std option to configure script.
hkratz Oct 11, 2021
bcf7cf6
Add --enable-debug-assertions-std option to configure script.
hkratz Oct 12, 2021
905ed5f
Make `rust.overflow-checks-std`option default to `rust.overflow-checks`.
hkratz Oct 12, 2021
f819e6d
suggestion for typoed crate or module
TaKO8Ki Sep 29, 2021
31265c6
Assemble the compiler when running `x.py build`
jyn514 Oct 11, 2021
9bb010e
Rollup merge of #89337 - mbrubeck:vec-leak, r=m-ou-se
the8472 Oct 13, 2021
0a998f8
Rollup merge of #89347 - TaKO8Ki:crate-or-module-typo, r=estebank
the8472 Oct 13, 2021
1ed61f5
Rollup merge of #89759 - jyn514:x-build-assemble, r=Mark-Simulacrum
the8472 Oct 13, 2021
0968607
Rollup merge of #89768 - hellow554:tests, r=Mark-Simulacrum
the8472 Oct 13, 2021
1d63deb
Rollup merge of #89777 - pierwill:fix-88233, r=Mark-Simulacrum
the8472 Oct 13, 2021
0b6839f
Rollup merge of #89781 - Wilfred:patch-2, r=JohnTitor
the8472 Oct 13, 2021
8852409
Rollup merge of #89782 - konan8205:develop, r=jsha
the8472 Oct 13, 2021
5a82eb3
Rollup merge of #89794 - jkugelman:must-use-to_value-conversions, r=j…
the8472 Oct 13, 2021
c4749bf
Rollup merge of #89814 - jkugelman:must-use-string-transforms-typo, r…
the8472 Oct 13, 2021
02cdfcc
Rollup merge of #89816 - Canop:master, r=Mark-Simulacrum
the8472 Oct 13, 2021
626dd87
Rollup merge of #89817 - m-ou-se:int-log-10-inline, r=the8472
the8472 Oct 13, 2021
67f3a5f
Rollup merge of #89818 - LingMan:map_or, r=oli-obk
the8472 Oct 13, 2021
c913af6
Rollup merge of #89828 - rusticstuff:overflow-check-options-take-two,…
the8472 Oct 13, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ __pycache__/
*$py.class

## Node
**node_modules
**package-lock.json
node_modules
package-lock.json

## Rustdoc GUI tests
src/test/rustdoc-gui/src/**.lock
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -841,7 +841,7 @@ impl<T: Idx> GrowableBitSet<T> {
#[inline]
pub fn contains(&self, elem: T) -> bool {
let (word_index, mask) = word_index_and_mask(elem);
if let Some(word) = self.bit_set.words.get(word_index) { (word & mask) != 0 } else { false }
self.bit_set.words.get(word_index).map_or(false, |word| (word & mask) != 0)
}
}

Expand Down
28 changes: 28 additions & 0 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,34 @@ impl<'a> Resolver<'a> {

err.emit();
}

crate fn find_similarly_named_module_or_crate(
&mut self,
ident: Symbol,
current_module: &Module<'a>,
) -> Option<Symbol> {
let mut candidates = self
.extern_prelude
.iter()
.map(|(ident, _)| ident.name)
.chain(
self.module_map
.iter()
.filter(|(_, module)| {
current_module.is_ancestor_of(module) && !ptr::eq(current_module, *module)
})
.map(|(_, module)| module.kind.name())
.flatten(),
)
.filter(|c| !c.to_string().is_empty())
.collect::<Vec<_>>();
candidates.sort();
candidates.dedup();
match find_best_match_for_name(&candidates, ident, None) {
Some(sugg) if sugg == ident => None,
sugg => sugg,
}
}
}

impl<'a, 'b> ImportResolver<'a, 'b> {
Expand Down
17 changes: 16 additions & 1 deletion compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2555,7 +2555,22 @@ impl<'a> Resolver<'a> {

(format!("use of undeclared type `{}`", ident), suggestion)
} else {
(format!("use of undeclared crate or module `{}`", ident), None)
(
format!("use of undeclared crate or module `{}`", ident),
self.find_similarly_named_module_or_crate(
ident.name,
&parent_scope.module,
)
.map(|sugg| {
(
vec![(ident.span, sugg.to_string())],
String::from(
"there is a crate or module with a similar name",
),
Applicability::MaybeIncorrect,
)
}),
)
}
} else {
let parent = path[i - 1].ident.name;
Expand Down
12 changes: 12 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,18 @@ changelog-seen = 2
# set this value to `true`.
#debug-logging = rust.debug-assertions (boolean)

# Whether or not overflow checks are enabled for the compiler and standard
# library.
#
# Defaults to rust.debug value
#overflow-checks = rust.debug (boolean)

# Whether or not overflow checks are enabled for the standard library.
# Overrides the `overflow-checks` option, if defined.
#
# Defaults to rust.overflow-checks value
#overflow-checks-std = rust.overflow-checks (boolean)

# Debuginfo level for most of Rust code, corresponds to the `-C debuginfo=N` option of `rustc`.
# `0` - no debug info
# `1` - line tables only - sufficient to generate backtraces that include line
Expand Down
2 changes: 1 addition & 1 deletion library/alloc/src/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ impl str {
/// [`make_ascii_uppercase`]: str::make_ascii_uppercase
/// [`to_uppercase`]: #method.to_uppercase
#[cfg(not(no_global_oom_handling))]
#[must_use = "to uppercase the value in-place, use `make_ascii_lowercase()`"]
#[must_use = "to uppercase the value in-place, use `make_ascii_uppercase()`"]
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
#[inline]
pub fn to_ascii_uppercase(&self) -> String {
Expand Down
8 changes: 5 additions & 3 deletions library/alloc/src/vec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,8 +1973,9 @@ impl<T, A: Allocator> Vec<T, A> {
/// `'a`. If the type has only static references, or none at all, then this
/// may be chosen to be `'static`.
///
/// This function is similar to the [`leak`][Box::leak] function on [`Box`]
/// except that there is no way to recover the leaked memory.
/// As of Rust 1.57, this method does not reallocate or shrink the `Vec`,
/// so the leaked allocation may include unused capacity that is not part
/// of the returned slice.
///
/// This function is mainly useful for data that lives for the remainder of
/// the program's life. Dropping the returned reference will cause a memory
Expand All @@ -1997,7 +1998,8 @@ impl<T, A: Allocator> Vec<T, A> {
where
A: 'a,
{
Box::leak(self.into_boxed_slice())
let mut me = ManuallyDrop::new(self);
unsafe { slice::from_raw_parts_mut(me.as_mut_ptr(), me.len) }
}

/// Returns the remaining spare capacity of the vector as a slice of
Expand Down
4 changes: 3 additions & 1 deletion library/core/src/char/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,9 +328,11 @@ impl char {
///
/// ```should_panic
/// // this panics
/// '1'.to_digit(37);
/// let _ = '1'.to_digit(37);
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_digit(self, radix: u32) -> Option<u32> {
assert!(radix <= 36, "to_digit: radix is too high (maximum 36)");
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ impl AsMut<str> for str {
///
/// However there is one case where `!` syntax can be used
/// before `!` is stabilized as a full-fledged type: in the position of a function’s return type.
/// Specifically, it is possible implementations for two different function pointer types:
/// Specifically, it is possible to have implementations for two different function pointer types:
///
/// ```
/// trait MyTrait {}
Expand Down
12 changes: 12 additions & 0 deletions library/core/src/num/int_log10.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod unchecked {
// 0 < val <= u8::MAX
#[inline]
pub const fn u8(val: u8) -> u32 {
let val = val as u32;

Expand All @@ -20,6 +21,7 @@ mod unchecked {
}

// 0 < val < 100_000
#[inline]
const fn less_than_5(val: u32) -> u32 {
// Similar to u8, when adding one of these constants to val,
// we get two possible bit patterns above the low 17 bits,
Expand All @@ -40,11 +42,13 @@ mod unchecked {
}

// 0 < val <= u16::MAX
#[inline]
pub const fn u16(val: u16) -> u32 {
less_than_5(val as u32)
}

// 0 < val <= u32::MAX
#[inline]
pub const fn u32(mut val: u32) -> u32 {
let mut log = 0;
if val >= 100_000 {
Expand All @@ -55,6 +59,7 @@ mod unchecked {
}

// 0 < val <= u64::MAX
#[inline]
pub const fn u64(mut val: u64) -> u32 {
let mut log = 0;
if val >= 10_000_000_000 {
Expand All @@ -69,6 +74,7 @@ mod unchecked {
}

// 0 < val <= u128::MAX
#[inline]
pub const fn u128(mut val: u128) -> u32 {
let mut log = 0;
if val >= 100_000_000_000_000_000_000_000_000_000_000 {
Expand All @@ -84,33 +90,39 @@ mod unchecked {
}

// 0 < val <= i8::MAX
#[inline]
pub const fn i8(val: i8) -> u32 {
u8(val as u8)
}

// 0 < val <= i16::MAX
#[inline]
pub const fn i16(val: i16) -> u32 {
u16(val as u16)
}

// 0 < val <= i32::MAX
#[inline]
pub const fn i32(val: i32) -> u32 {
u32(val as u32)
}

// 0 < val <= i64::MAX
#[inline]
pub const fn i64(val: i64) -> u32 {
u64(val as u64)
}

// 0 < val <= i128::MAX
#[inline]
pub const fn i128(val: i128) -> u32 {
u128(val as u128)
}
}

macro_rules! impl_checked {
($T:ident) => {
#[inline]
pub const fn $T(val: $T) -> Option<u32> {
if val > 0 { Some(unchecked::$T(val)) } else { None }
}
Expand Down
4 changes: 4 additions & 0 deletions library/core/src/ptr/non_null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ impl<T: ?Sized> NonNull<T> {
/// The pointer can be later reconstructed with [`NonNull::from_raw_parts`].
#[unstable(feature = "ptr_metadata", issue = "81513")]
#[rustc_const_unstable(feature = "ptr_metadata", issue = "81513")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_raw_parts(self) -> (NonNull<()>, <T as super::Pointee>::Metadata) {
(self.cast(), super::metadata(self.as_ptr()))
Expand Down Expand Up @@ -386,6 +388,8 @@ impl<T: ?Sized> NonNull<T> {
/// ```
#[stable(feature = "nonnull_cast", since = "1.27.0")]
#[rustc_const_stable(feature = "const_nonnull_cast", since = "1.36.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn cast<U>(self) -> NonNull<U> {
// SAFETY: `self` is a `NonNull` pointer which is necessarily non-null
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/ffi/c_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1342,6 +1342,8 @@ impl CStr {
/// assert_eq!(cstr.to_bytes(), b"foo");
/// ```
#[inline]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn to_bytes(&self) -> &[u8] {
let bytes = self.to_bytes_with_nul();
Expand All @@ -1367,6 +1369,8 @@ impl CStr {
/// assert_eq!(cstr.to_bytes_with_nul(), b"foo\0");
/// ```
#[inline]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn to_bytes_with_nul(&self) -> &[u8] {
unsafe { &*(&self.inner as *const [c_char] as *const [u8]) }
Expand Down Expand Up @@ -1437,6 +1441,8 @@ impl CStr {
/// Cow::Owned(String::from("Hello �World")) as Cow<'_, str>
/// );
/// ```
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "cstr_to_str", since = "1.4.0")]
pub fn to_string_lossy(&self) -> Cow<'_, str> {
String::from_utf8_lossy(self.to_bytes())
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/ffi/os_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,8 @@ impl OsStr {
/// assert_eq!(os_str.to_str(), Some("foo"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_str(&self) -> Option<&str> {
self.inner.to_str()
Expand Down Expand Up @@ -627,6 +629,8 @@ impl OsStr {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_string_lossy(&self) -> Cow<'_, str> {
self.inner.to_string_lossy()
Expand All @@ -644,6 +648,8 @@ impl OsStr {
/// assert_eq!(os_string, OsString::from("foo"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_os_string(&self) -> OsString {
OsString { inner: self.inner.to_owned() }
Expand Down
14 changes: 13 additions & 1 deletion library/std/src/net/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ impl IpAddr {
/// assert_eq!(IpAddr::V6(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1)).to_canonical().is_loopback(), true);
/// ```
#[inline]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[rustc_const_unstable(feature = "const_ip", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
pub const fn to_canonical(&self) -> IpAddr {
Expand Down Expand Up @@ -901,6 +903,8 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_ipv6_compatible(&self) -> Ipv6Addr {
let [a, b, c, d] = self.octets();
Expand All @@ -926,6 +930,8 @@ impl Ipv4Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv4", since = "1.50.0")]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_ipv6_mapped(&self) -> Ipv6Addr {
let [a, b, c, d] = self.octets();
Expand Down Expand Up @@ -1648,6 +1654,8 @@ impl Ipv6Addr {
/// ```
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_ipv4_mapped(&self) -> Option<Ipv4Addr> {
match self.octets() {
Expand Down Expand Up @@ -1685,6 +1693,8 @@ impl Ipv6Addr {
/// ```
#[rustc_const_stable(feature = "const_ipv6", since = "1.50.0")]
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_ipv4(&self) -> Option<Ipv4Addr> {
if let [0, 0, 0, 0, 0, 0 | 0xffff, ab, cd] = self.segments() {
Expand All @@ -1708,9 +1718,11 @@ impl Ipv6Addr {
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).is_loopback(), false);
/// assert_eq!(Ipv6Addr::new(0, 0, 0, 0, 0, 0xffff, 0x7f00, 0x1).to_canonical().is_loopback(), true);
/// ```
#[inline]
#[rustc_const_unstable(feature = "const_ipv6", issue = "76205")]
#[unstable(feature = "ip", issue = "27709")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub const fn to_canonical(&self) -> IpAddr {
if let Some(mapped) = self.to_ipv4_mapped() {
return IpAddr::V4(mapped);
Expand Down
6 changes: 6 additions & 0 deletions library/std/src/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1952,6 +1952,8 @@ impl Path {
/// assert_eq!(path.to_str(), Some("foo.txt"));
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_str(&self) -> Option<&str> {
self.inner.to_str()
Expand All @@ -1978,6 +1980,8 @@ impl Path {
/// Had `path` contained invalid unicode, the `to_string_lossy` call might
/// have returned `"fo�.txt"`.
#[stable(feature = "rust1", since = "1.0.0")]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[inline]
pub fn to_string_lossy(&self) -> Cow<'_, str> {
self.inner.to_string_lossy()
Expand All @@ -1994,6 +1998,8 @@ impl Path {
/// assert_eq!(path_buf, std::path::PathBuf::from("foo.txt"));
/// ```
#[rustc_conversion_suggestion]
#[must_use = "this returns the result of the operation, \
without modifying the original"]
#[stable(feature = "rust1", since = "1.0.0")]
pub fn to_path_buf(&self) -> PathBuf {
PathBuf::from(self.inner.to_os_string())
Expand Down
Loading