Skip to content

Commit e7acd07

Browse files
committed
Auto merge of #107828 - compiler-errors:rollup-gyj6dgj, r=compiler-errors
Rollup of 9 pull requests Successful merges: - #107317 (Implement `AsFd` and `AsRawFd` for `Rc`) - #107429 (Stabilize feature `cstr_from_bytes_until_nul`) - #107713 (Extend `BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE`.) - #107761 (Replace a command line flag with an env var to allow tools to initialize the tracing loggers at their own discretion) - #107790 ( x.py fails all downloads that use a tempdir with snap curl #107722) - #107799 (correctly update goals in the cache) - #107813 (Do not eagerly recover for bad `impl Trait` types in macros) - #107817 (rustdoc: use svgo to shrink `wheel.svg`) - #107819 (Set `rust-analyzer.check.invocationLocation` to `root`) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 575d424 + 3e07554 commit e7acd07

File tree

28 files changed

+227
-94
lines changed

28 files changed

+227
-94
lines changed

compiler/rustc_builtin_macros/src/deriving/generic/mod.rs

+35-20
Original file line numberDiff line numberDiff line change
@@ -1557,31 +1557,46 @@ impl<'a> TraitDef<'a> {
15571557
}),
15581558
),
15591559
);
1560-
// In general, fields in packed structs are copied via a
1561-
// block, e.g. `&{self.0}`. The one exception is `[u8]`
1562-
// fields, which cannot be copied and also never cause
1563-
// unaligned references. This exception is allowed to
1564-
// handle the `FlexZeroSlice` type in the `zerovec` crate
1565-
// within `icu4x-0.9.0`.
1566-
//
1567-
// Once use of `icu4x-0.9.0` has dropped sufficiently, this
1568-
// exception should be removed.
1569-
let is_u8_slice = if let TyKind::Slice(ty) = &struct_field.ty.kind &&
1570-
let TyKind::Path(None, rustc_ast::Path { segments, .. }) = &ty.kind &&
1571-
let [seg] = segments.as_slice() &&
1572-
seg.ident.name == sym::u8 && seg.args.is_none()
1573-
{
1574-
true
1575-
} else {
1576-
false
1577-
};
15781560
if is_packed {
1579-
if is_u8_slice {
1561+
// In general, fields in packed structs are copied via a
1562+
// block, e.g. `&{self.0}`. The two exceptions are `[u8]`
1563+
// and `str` fields, which cannot be copied and also never
1564+
// cause unaligned references. These exceptions are allowed
1565+
// to handle the `FlexZeroSlice` type in the `zerovec`
1566+
// crate within `icu4x-0.9.0`.
1567+
//
1568+
// Once use of `icu4x-0.9.0` has dropped sufficiently, this
1569+
// exception should be removed.
1570+
let is_simple_path = |ty: &P<ast::Ty>, sym| {
1571+
if let TyKind::Path(None, ast::Path { segments, .. }) = &ty.kind &&
1572+
let [seg] = segments.as_slice() &&
1573+
seg.ident.name == sym && seg.args.is_none()
1574+
{
1575+
true
1576+
} else {
1577+
false
1578+
}
1579+
};
1580+
1581+
let exception = if let TyKind::Slice(ty) = &struct_field.ty.kind &&
1582+
is_simple_path(ty, sym::u8)
1583+
{
1584+
Some("byte")
1585+
} else if is_simple_path(&struct_field.ty, sym::str) {
1586+
Some("string")
1587+
} else {
1588+
None
1589+
};
1590+
1591+
if let Some(ty) = exception {
15801592
cx.sess.parse_sess.buffer_lint_with_diagnostic(
15811593
BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
15821594
sp,
15831595
ast::CRATE_NODE_ID,
1584-
"byte slice in a packed struct that derives a built-in trait",
1596+
&format!(
1597+
"{} slice in a packed struct that derives a built-in trait",
1598+
ty
1599+
),
15851600
rustc_lint_defs::BuiltinLintDiagnostics::ByteSliceInPackedStructWithDerive
15861601
);
15871602
} else {

compiler/rustc_driver_impl/src/lib.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -229,10 +229,6 @@ fn run_compiler(
229229
registry: diagnostics_registry(),
230230
};
231231

232-
if !tracing::dispatcher::has_been_set() {
233-
init_rustc_env_logger_with_backtrace_option(&config.opts.unstable_opts.log_backtrace);
234-
}
235-
236232
match make_input(config.opts.error_format, &matches.free) {
237233
Err(reported) => return Err(reported),
238234
Ok(Some(input)) => {
@@ -1251,16 +1247,7 @@ pub fn install_ice_hook() {
12511247
/// This allows tools to enable rust logging without having to magically match rustc's
12521248
/// tracing crate version.
12531249
pub fn init_rustc_env_logger() {
1254-
init_rustc_env_logger_with_backtrace_option(&None);
1255-
}
1256-
1257-
/// This allows tools to enable rust logging without having to magically match rustc's
1258-
/// tracing crate version. In contrast to `init_rustc_env_logger` it allows you to
1259-
/// choose a target module you wish to show backtraces along with its logging.
1260-
pub fn init_rustc_env_logger_with_backtrace_option(backtrace_target: &Option<String>) {
1261-
if let Err(error) = rustc_log::init_rustc_env_logger_with_backtrace_option(backtrace_target) {
1262-
early_error(ErrorOutputType::default(), &error.to_string());
1263-
}
1250+
init_env_logger("RUSTC_LOG");
12641251
}
12651252

12661253
/// This allows tools to enable rust logging without having to magically match rustc's
@@ -1324,6 +1311,7 @@ mod signal_handler {
13241311
pub fn main() -> ! {
13251312
let start_time = Instant::now();
13261313
let start_rss = get_resident_set_size();
1314+
init_rustc_env_logger();
13271315
signal_handler::install();
13281316
let mut callbacks = TimePassesCallbacks::default();
13291317
install_ice_hook();

compiler/rustc_interface/src/tests.rs

-1
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,6 @@ fn test_unstable_options_tracking_hash() {
758758
tracked!(link_only, true);
759759
tracked!(llvm_plugins, vec![String::from("plugin_name")]);
760760
tracked!(location_detail, LocationDetail { file: true, line: false, column: false });
761-
tracked!(log_backtrace, Some("filter".to_string()));
762761
tracked!(maximal_hir_to_mir_coverage, true);
763762
tracked!(merge_functions, Some(MergeFunctions::Disabled));
764763
tracked!(mir_emit_retag, true);

compiler/rustc_lint_defs/src/builtin.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -4073,7 +4073,8 @@ declare_lint! {
40734073

40744074
declare_lint! {
40754075
/// The `byte_slice_in_packed_struct_with_derive` lint detects cases where a byte slice field
4076-
/// (`[u8]`) is used in a `packed` struct that derives one or more built-in traits.
4076+
/// (`[u8]`) or string slice field (`str`) is used in a `packed` struct that derives one or
4077+
/// more built-in traits.
40774078
///
40784079
/// ### Example
40794080
///
@@ -4091,11 +4092,11 @@ declare_lint! {
40914092
/// ### Explanation
40924093
///
40934094
/// This was previously accepted but is being phased out, because fields in packed structs are
4094-
/// now required to implement `Copy` for `derive` to work. Byte slices are a temporary
4095-
/// exception because certain crates depended on them.
4095+
/// now required to implement `Copy` for `derive` to work. Byte slices and string slices are a
4096+
/// temporary exception because certain crates depended on them.
40964097
pub BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE,
40974098
Warn,
4098-
"`[u8]` slice used in a packed struct with `derive`",
4099+
"`[u8]` or `str` used in a packed struct with `derive`",
40994100
@future_incompatible = FutureIncompatibleInfo {
41004101
reference: "issue #107457 <https://github.com/rust-lang/rust/issues/107457>",
41014102
reason: FutureIncompatibilityReason::FutureReleaseErrorReportNow,

compiler/rustc_log/src/lib.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -54,25 +54,12 @@ use tracing_subscriber::fmt::{
5454
use tracing_subscriber::layer::SubscriberExt;
5555

5656
pub fn init_rustc_env_logger() -> Result<(), Error> {
57-
init_rustc_env_logger_with_backtrace_option(&None)
58-
}
59-
60-
pub fn init_rustc_env_logger_with_backtrace_option(
61-
backtrace_target: &Option<String>,
62-
) -> Result<(), Error> {
63-
init_env_logger_with_backtrace_option("RUSTC_LOG", backtrace_target)
57+
init_env_logger("RUSTC_LOG")
6458
}
6559

6660
/// In contrast to `init_rustc_env_logger` this allows you to choose an env var
6761
/// other than `RUSTC_LOG`.
6862
pub fn init_env_logger(env: &str) -> Result<(), Error> {
69-
init_env_logger_with_backtrace_option(env, &None)
70-
}
71-
72-
pub fn init_env_logger_with_backtrace_option(
73-
env: &str,
74-
backtrace_target: &Option<String>,
75-
) -> Result<(), Error> {
7663
let filter = match env::var(env) {
7764
Ok(env) => EnvFilter::new(env),
7865
_ => EnvFilter::default().add_directive(Directive::from(LevelFilter::WARN)),
@@ -106,16 +93,16 @@ pub fn init_env_logger_with_backtrace_option(
10693
let layer = layer.with_thread_ids(true).with_thread_names(true);
10794

10895
let subscriber = tracing_subscriber::Registry::default().with(filter).with(layer);
109-
match backtrace_target {
110-
Some(str) => {
96+
match env::var(format!("{env}_BACKTRACE")) {
97+
Ok(str) => {
11198
let fmt_layer = tracing_subscriber::fmt::layer()
11299
.with_writer(io::stderr)
113100
.without_time()
114101
.event_format(BacktraceFormatter { backtrace_target: str.to_string() });
115102
let subscriber = subscriber.with(fmt_layer);
116103
tracing::subscriber::set_global_default(subscriber).unwrap();
117104
}
118-
None => {
105+
Err(_) => {
119106
tracing::subscriber::set_global_default(subscriber).unwrap();
120107
}
121108
};

compiler/rustc_parse/src/parser/ty.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -694,8 +694,9 @@ impl<'a> Parser<'a> {
694694
// `where`, so stop if it's it.
695695
// We also continue if we find types (not traits), again for error recovery.
696696
while self.can_begin_bound()
697-
|| self.token.can_begin_type()
698-
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))
697+
|| (self.may_recover()
698+
&& (self.token.can_begin_type()
699+
|| (self.token.is_reserved_ident() && !self.token.is_keyword(kw::Where))))
699700
{
700701
if self.token.is_keyword(kw::Dyn) {
701702
// Account for `&dyn Trait + dyn Other`.

compiler/rustc_session/src/options.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1413,8 +1413,6 @@ options! {
14131413
"what location details should be tracked when using caller_location, either \
14141414
`none`, or a comma separated list of location details, for which \
14151415
valid options are `file`, `line`, and `column` (default: `file,line,column`)"),
1416-
log_backtrace: Option<String> = (None, parse_opt_string, [TRACKED],
1417-
"add a backtrace along with logging"),
14181416
ls: bool = (false, parse_bool, [UNTRACKED],
14191417
"list the symbols defined by a library crate (default: no)"),
14201418
macro_backtrace: bool = (false, parse_bool, [UNTRACKED],

compiler/rustc_trait_selection/src/solve/search_graph/mod.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use cache::ProvisionalCache;
77
use overflow::OverflowData;
88
use rustc_index::vec::IndexVec;
99
use rustc_middle::ty::TyCtxt;
10-
use std::collections::hash_map::Entry;
10+
use std::{collections::hash_map::Entry, mem};
1111

1212
rustc_index::newtype_index! {
1313
pub struct StackDepth {}
@@ -134,12 +134,15 @@ impl<'tcx> SearchGraph<'tcx> {
134134
let provisional_entry_index = *cache.lookup_table.get(&goal).unwrap();
135135
let provisional_entry = &mut cache.entries[provisional_entry_index];
136136
let depth = provisional_entry.depth;
137+
// We eagerly update the response in the cache here. If we have to reevaluate
138+
// this goal we use the new response when hitting a cycle, and we definitely
139+
// want to access the final response whenever we look at the cache.
140+
let prev_response = mem::replace(&mut provisional_entry.response, response);
141+
137142
// Was the current goal the root of a cycle and was the provisional response
138143
// different from the final one.
139-
if has_been_used && provisional_entry.response != response {
140-
// If so, update the provisional reponse for this goal...
141-
provisional_entry.response = response;
142-
// ...remove all entries whose result depends on this goal
144+
if has_been_used && prev_response != response {
145+
// If so, remove all entries whose result depends on this goal
143146
// from the provisional cache...
144147
//
145148
// That's not completely correct, as a nested goal can also

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@
116116
#![feature(const_eval_select)]
117117
#![feature(const_pin)]
118118
#![feature(const_waker)]
119-
#![feature(cstr_from_bytes_until_nul)]
120119
#![feature(dispatch_from_dyn)]
121120
#![feature(error_generic_member_access)]
122121
#![feature(error_in_core)]

library/core/src/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ impl Error for crate::ffi::FromBytesWithNulError {
505505
}
506506
}
507507

508-
#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")]
508+
#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
509509
impl Error for crate::ffi::FromBytesUntilNulError {}
510510

511511
#[unstable(feature = "get_many_mut", issue = "104642")]

library/core/src/ffi/c_str.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ impl FromBytesWithNulError {
150150
/// This error is created by the [`CStr::from_bytes_until_nul`] method.
151151
///
152152
#[derive(Clone, PartialEq, Eq, Debug)]
153-
#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")]
153+
#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
154154
pub struct FromBytesUntilNulError(());
155155

156-
#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")]
156+
#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
157157
impl fmt::Display for FromBytesUntilNulError {
158158
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
159159
write!(f, "data provided does not contain a nul")
@@ -306,8 +306,6 @@ impl CStr {
306306
///
307307
/// # Examples
308308
/// ```
309-
/// #![feature(cstr_from_bytes_until_nul)]
310-
///
311309
/// use std::ffi::CStr;
312310
///
313311
/// let mut buffer = [0u8; 16];
@@ -322,8 +320,9 @@ impl CStr {
322320
/// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA");
323321
/// ```
324322
///
325-
#[unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")]
326-
#[rustc_const_unstable(feature = "cstr_from_bytes_until_nul", issue = "95027")]
323+
#[rustc_allow_const_fn_unstable(const_slice_index)]
324+
#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
325+
#[rustc_const_stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
327326
pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> {
328327
let nul_pos = memchr::memchr(0, bytes);
329328
match nul_pos {

library/core/src/slice/memchr.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ const USIZE_BYTES: usize = mem::size_of::<usize>();
1616
/// bytes where the borrow propagated all the way to the most significant
1717
/// bit."
1818
#[inline]
19+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
1920
const fn contains_zero_byte(x: usize) -> bool {
2021
x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0
2122
}
2223

23-
#[cfg(target_pointer_width = "16")]
2424
#[inline]
25+
#[cfg(target_pointer_width = "16")]
26+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
2527
const fn repeat_byte(b: u8) -> usize {
2628
(b as usize) << 8 | b as usize
2729
}
2830

29-
#[cfg(not(target_pointer_width = "16"))]
3031
#[inline]
32+
#[cfg(not(target_pointer_width = "16"))]
33+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
3134
const fn repeat_byte(b: u8) -> usize {
3235
(b as usize) * (usize::MAX / 255)
3336
}
3437

3538
/// Returns the first index matching the byte `x` in `text`.
36-
#[must_use]
3739
#[inline]
40+
#[must_use]
41+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
3842
pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
3943
// Fast path for small slices.
4044
if text.len() < 2 * USIZE_BYTES {
@@ -45,6 +49,7 @@ pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
4549
}
4650

4751
#[inline]
52+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
4853
const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
4954
let mut i = 0;
5055

@@ -60,6 +65,10 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
6065
None
6166
}
6267

68+
#[rustc_allow_const_fn_unstable(const_cmp)]
69+
#[rustc_allow_const_fn_unstable(const_slice_index)]
70+
#[rustc_allow_const_fn_unstable(const_align_offset)]
71+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
6372
const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
6473
// Scan for a single byte value by reading two `usize` words at a time.
6574
//

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,6 @@
278278
#![feature(char_error_internals)]
279279
#![feature(char_internals)]
280280
#![feature(core_intrinsics)]
281-
#![feature(cstr_from_bytes_until_nul)]
282281
#![feature(cstr_internals)]
283282
#![feature(duration_constants)]
284283
#![feature(error_generic_member_access)]

library/std/src/os/fd/owned.rs

+8
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,14 @@ impl<T: AsFd> AsFd for crate::sync::Arc<T> {
396396
}
397397
}
398398

399+
#[stable(feature = "asfd_rc", since = "CURRENT_RUSTC_VERSION")]
400+
impl<T: AsFd> AsFd for crate::rc::Rc<T> {
401+
#[inline]
402+
fn as_fd(&self) -> BorrowedFd<'_> {
403+
(**self).as_fd()
404+
}
405+
}
406+
399407
#[stable(feature = "asfd_ptrs", since = "1.64.0")]
400408
impl<T: AsFd> AsFd for Box<T> {
401409
#[inline]

library/std/src/os/fd/raw.rs

+8
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ impl<T: AsRawFd> AsRawFd for crate::sync::Arc<T> {
244244
}
245245
}
246246

247+
#[stable(feature = "asfd_rc", since = "CURRENT_RUSTC_VERSION")]
248+
impl<T: AsRawFd> AsRawFd for crate::rc::Rc<T> {
249+
#[inline]
250+
fn as_raw_fd(&self) -> RawFd {
251+
(**self).as_raw_fd()
252+
}
253+
}
254+
247255
#[stable(feature = "asrawfd_ptrs", since = "1.63.0")]
248256
impl<T: AsRawFd> AsRawFd for Box<T> {
249257
#[inline]

src/bootstrap/bootstrap.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,16 @@ def _download(path, url, probably_big, verbose, exception):
8787
# If curl is not present on Win32, we should not sys.exit
8888
# but raise `CalledProcessError` or `OSError` instead
8989
require(["curl", "--version"], exception=platform_is_win32)
90-
run(["curl", option,
91-
"-L", # Follow redirect.
92-
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
93-
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
94-
"--retry", "3", "-Sf", "-o", path, url],
95-
verbose=verbose,
96-
exception=True, # Will raise RuntimeError on failure
97-
)
90+
with open(path, "wb") as outfile:
91+
run(["curl", option,
92+
"-L", # Follow redirect.
93+
"-y", "30", "-Y", "10", # timeout if speed is < 10 bytes/sec for > 30 seconds
94+
"--connect-timeout", "30", # timeout if cannot connect within 30 seconds
95+
"--retry", "3", "-Sf", url],
96+
stdout=outfile, #Implements cli redirect operator '>'
97+
verbose=verbose,
98+
exception=True, # Will raise RuntimeError on failure
99+
)
98100
except (subprocess.CalledProcessError, OSError, RuntimeError):
99101
# see http://serverfault.com/questions/301128/how-to-download
100102
if platform_is_win32:

0 commit comments

Comments
 (0)