Skip to content

Commit 5afdf5d

Browse files
committed
Auto merge of rust-lang#150669 - Zalathar:rollup-7ar4hqp, r=Zalathar
Rollup of 7 pull requests Successful merges: - rust-lang#150201 (compiletest: Support revisions in debuginfo (read: debugger) tests) - rust-lang#150642 (mutex.rs: remove needless-maybe-unsized bounds) - rust-lang#150643 (vec in-place-drop: avoid creating an intermediate slice) - rust-lang#150650 (Forbid generic parameters in types of #[type_const] items) - rust-lang#150658 (Clarify panic conditions in `Iterator::last`) - rust-lang#150659 (Add missing translator resources for interface parse_cfg and parse_check_cfg) - rust-lang#150666 (Fix ambig-unambig-ty-and-consts link) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f8b1d59 + 85dc7c2 commit 5afdf5d

26 files changed

+314
-58
lines changed

compiler/rustc_hir/src/hir.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ impl<'hir> ConstItemRhs<'hir> {
440440
/// versus const args that are literals or have arbitrary computations (e.g., `{ 1 + 3 }`).
441441
///
442442
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
443-
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
443+
/// <https://rustc-dev-guide.rust-lang.org/ambig-unambig-ty-and-consts.html>
444444
#[derive(Clone, Copy, Debug, HashStable_Generic)]
445445
#[repr(C)]
446446
pub struct ConstArg<'hir, Unambig = ()> {
@@ -3374,7 +3374,7 @@ pub enum AmbigArg {}
33743374
/// Represents a type in the `HIR`.
33753375
///
33763376
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
3377-
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
3377+
/// <https://rustc-dev-guide.rust-lang.org/ambig-unambig-ty-and-consts.html>
33783378
#[derive(Debug, Clone, Copy, HashStable_Generic)]
33793379
#[repr(C)]
33803380
pub struct Ty<'hir, Unambig = ()> {
@@ -3713,7 +3713,7 @@ pub enum InferDelegationKind {
37133713
/// The various kinds of types recognized by the compiler.
37143714
///
37153715
/// For an explanation of the `Unambig` generic parameter see the dev-guide:
3716-
/// <https://rustc-dev-guide.rust-lang.org/hir/ambig-unambig-ty-and-consts.html>
3716+
/// <https://rustc-dev-guide.rust-lang.org/ambig-unambig-ty-and-consts.html>
37173717
// SAFETY: `repr(u8)` is required so that `TyKind<()>` and `TyKind<!>` are layout compatible
37183718
#[repr(u8, C)]
37193719
#[derive(Debug, Clone, Copy, HashStable_Generic)]

compiler/rustc_interface/src/interface.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ pub(crate) fn parse_cfg(dcx: DiagCtxtHandle<'_>, cfgs: Vec<String>) -> Cfg {
5555
cfgs.into_iter()
5656
.map(|s| {
5757
let psess = ParseSess::emitter_with_note(
58-
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
58+
vec![
59+
crate::DEFAULT_LOCALE_RESOURCE,
60+
rustc_parse::DEFAULT_LOCALE_RESOURCE,
61+
rustc_session::DEFAULT_LOCALE_RESOURCE,
62+
],
5963
format!("this occurred on the command line: `--cfg={s}`"),
6064
);
6165
let filename = FileName::cfg_spec_source_code(&s);
@@ -129,7 +133,11 @@ pub(crate) fn parse_check_cfg(dcx: DiagCtxtHandle<'_>, specs: Vec<String>) -> Ch
129133

130134
for s in specs {
131135
let psess = ParseSess::emitter_with_note(
132-
vec![crate::DEFAULT_LOCALE_RESOURCE, rustc_parse::DEFAULT_LOCALE_RESOURCE],
136+
vec![
137+
crate::DEFAULT_LOCALE_RESOURCE,
138+
rustc_parse::DEFAULT_LOCALE_RESOURCE,
139+
rustc_session::DEFAULT_LOCALE_RESOURCE,
140+
],
133141
format!("this occurred on the command line: `--check-cfg={s}`"),
134142
);
135143
let filename = FileName::cfg_spec_source_code(&s);

compiler/rustc_resolve/src/late.rs

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2851,6 +2851,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28512851
ref define_opaque,
28522852
..
28532853
}) => {
2854+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
28542855
self.with_generic_param_rib(
28552856
&generics.params,
28562857
RibKind::Item(
@@ -2869,7 +2870,22 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
28692870

28702871
this.with_lifetime_rib(
28712872
LifetimeRibKind::Elided(LifetimeRes::Static),
2872-
|this| this.visit_ty(ty),
2873+
|this| {
2874+
if is_type_const
2875+
&& !this.r.tcx.features().generic_const_parameter_types()
2876+
{
2877+
this.with_rib(TypeNS, RibKind::ConstParamTy, |this| {
2878+
this.with_rib(ValueNS, RibKind::ConstParamTy, |this| {
2879+
this.with_lifetime_rib(
2880+
LifetimeRibKind::ConstParamTy,
2881+
|this| this.visit_ty(ty),
2882+
)
2883+
})
2884+
});
2885+
} else {
2886+
this.visit_ty(ty);
2887+
}
2888+
},
28732889
);
28742890

28752891
if let Some(rhs) = rhs {
@@ -3209,6 +3225,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32093225
define_opaque,
32103226
..
32113227
}) => {
3228+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
32123229
self.with_generic_param_rib(
32133230
&generics.params,
32143231
RibKind::AssocItem,
@@ -3223,7 +3240,20 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
32233240
},
32243241
|this| {
32253242
this.visit_generics(generics);
3226-
this.visit_ty(ty);
3243+
if is_type_const
3244+
&& !this.r.tcx.features().generic_const_parameter_types()
3245+
{
3246+
this.with_rib(TypeNS, RibKind::ConstParamTy, |this| {
3247+
this.with_rib(ValueNS, RibKind::ConstParamTy, |this| {
3248+
this.with_lifetime_rib(
3249+
LifetimeRibKind::ConstParamTy,
3250+
|this| this.visit_ty(ty),
3251+
)
3252+
})
3253+
});
3254+
} else {
3255+
this.visit_ty(ty);
3256+
}
32273257

32283258
// Only impose the restrictions of `ConstRibKind` for an
32293259
// actual constant expression in a provided default.
@@ -3417,6 +3447,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34173447
..
34183448
}) => {
34193449
debug!("resolve_implementation AssocItemKind::Const");
3450+
let is_type_const = attr::contains_name(&item.attrs, sym::type_const);
34203451
self.with_generic_param_rib(
34213452
&generics.params,
34223453
RibKind::AssocItem,
@@ -3453,7 +3484,28 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {
34533484
);
34543485

34553486
this.visit_generics(generics);
3456-
this.visit_ty(ty);
3487+
if is_type_const
3488+
&& !this
3489+
.r
3490+
.tcx
3491+
.features()
3492+
.generic_const_parameter_types()
3493+
{
3494+
this.with_rib(TypeNS, RibKind::ConstParamTy, |this| {
3495+
this.with_rib(
3496+
ValueNS,
3497+
RibKind::ConstParamTy,
3498+
|this| {
3499+
this.with_lifetime_rib(
3500+
LifetimeRibKind::ConstParamTy,
3501+
|this| this.visit_ty(ty),
3502+
)
3503+
},
3504+
)
3505+
});
3506+
} else {
3507+
this.visit_ty(ty);
3508+
}
34573509
if let Some(rhs) = rhs {
34583510
// We allow arbitrary const expressions inside of associated consts,
34593511
// even if they are potentially not const evaluatable.

library/alloc/src/vec/in_place_drop.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use core::marker::PhantomData;
22
use core::ptr::{self, NonNull, drop_in_place};
3-
use core::slice::{self};
43

54
use crate::alloc::Global;
65
use crate::raw_vec::RawVec;
@@ -22,7 +21,7 @@ impl<T> Drop for InPlaceDrop<T> {
2221
#[inline]
2322
fn drop(&mut self) {
2423
unsafe {
25-
ptr::drop_in_place(slice::from_raw_parts_mut(self.inner, self.len()));
24+
ptr::drop_in_place(ptr::slice_from_raw_parts_mut(self.inner, self.len()));
2625
}
2726
}
2827
}

library/core/src/iter/traits/iterator.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ pub trait Iterator {
238238
///
239239
/// # Panics
240240
///
241-
/// This function might panic if the iterator has more than [`usize::MAX`]
242-
/// elements.
241+
/// This function might panic if the iterator is infinite.
243242
///
244243
/// # Examples
245244
///

library/std/src/sync/nonpoison/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ impl<T> From<T> for Mutex<T> {
422422
}
423423

424424
#[unstable(feature = "nonpoison_mutex", issue = "134645")]
425-
impl<T: ?Sized + Default> Default for Mutex<T> {
425+
impl<T: Default> Default for Mutex<T> {
426426
/// Creates a `Mutex<T>`, with the `Default` value for T.
427427
fn default() -> Mutex<T> {
428428
Mutex::new(Default::default())

library/std/src/sync/poison/mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ impl<T> From<T> for Mutex<T> {
688688
}
689689

690690
#[stable(feature = "mutex_default", since = "1.10.0")]
691-
impl<T: ?Sized + Default> Default for Mutex<T> {
691+
impl<T: Default> Default for Mutex<T> {
692692
/// Creates a `Mutex<T>`, with the `Default` value for T.
693693
fn default() -> Mutex<T> {
694694
Mutex::new(Default::default())

src/tools/compiletest/src/directives.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::directives::directive_names::{
1515
};
1616
pub(crate) use crate::directives::file::FileDirectives;
1717
use crate::directives::handlers::DIRECTIVE_HANDLERS_MAP;
18-
use crate::directives::line::{DirectiveLine, line_directive};
18+
use crate::directives::line::DirectiveLine;
1919
use crate::directives::needs::CachedNeedsConditions;
2020
use crate::edition::{Edition, parse_edition};
2121
use crate::errors::ErrorKind;
@@ -29,6 +29,7 @@ mod directive_names;
2929
mod file;
3030
mod handlers;
3131
mod line;
32+
pub(crate) use line::line_directive;
3233
mod line_number;
3334
pub(crate) use line_number::LineNumber;
3435
mod needs;

src/tools/compiletest/src/runtest/debugger.rs

Lines changed: 32 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io::{BufRead, BufReader};
44

55
use camino::{Utf8Path, Utf8PathBuf};
66

7-
use crate::directives::LineNumber;
7+
use crate::directives::{LineNumber, line_directive};
88
use crate::runtest::ProcRes;
99

1010
/// Representation of information to invoke a debugger and check its output
@@ -17,10 +17,16 @@ pub(super) struct DebuggerCommands {
1717
check_lines: Vec<(LineNumber, String)>,
1818
/// Source file name
1919
file: Utf8PathBuf,
20+
/// The revision being tested, if any
21+
revision: Option<String>,
2022
}
2123

2224
impl DebuggerCommands {
23-
pub fn parse_from(file: &Utf8Path, debugger_prefix: &str) -> Result<Self, String> {
25+
pub fn parse_from(
26+
file: &Utf8Path,
27+
debugger_prefix: &str,
28+
test_revision: Option<&str>,
29+
) -> Result<Self, String> {
2430
let command_directive = format!("{debugger_prefix}-command");
2531
let check_directive = format!("{debugger_prefix}-check");
2632

@@ -37,19 +43,33 @@ impl DebuggerCommands {
3743
continue;
3844
}
3945

40-
let Some(line) = line.trim_start().strip_prefix("//@").map(str::trim_start) else {
46+
let Some(directive) = line_directive(file, line_number, &line) else {
4147
continue;
4248
};
4349

44-
if let Some(command) = parse_name_value(&line, &command_directive) {
45-
commands.push(command);
50+
if !directive.applies_to_test_revision(test_revision) {
51+
continue;
4652
}
47-
if let Some(pattern) = parse_name_value(&line, &check_directive) {
48-
check_lines.push((line_number, pattern));
53+
54+
if directive.name == command_directive
55+
&& let Some(command) = directive.value_after_colon()
56+
{
57+
commands.push(command.to_string());
58+
}
59+
if directive.name == check_directive
60+
&& let Some(pattern) = directive.value_after_colon()
61+
{
62+
check_lines.push((line_number, pattern.to_string()));
4963
}
5064
}
5165

52-
Ok(Self { commands, breakpoint_lines, check_lines, file: file.to_path_buf() })
66+
Ok(Self {
67+
commands,
68+
breakpoint_lines,
69+
check_lines,
70+
file: file.to_path_buf(),
71+
revision: test_revision.map(str::to_owned),
72+
})
5373
}
5474

5575
/// Given debugger output and lines to check, ensure that every line is
@@ -81,9 +101,11 @@ impl DebuggerCommands {
81101
Ok(())
82102
} else {
83103
let fname = self.file.file_name().unwrap();
104+
let revision_suffix =
105+
self.revision.as_ref().map_or(String::new(), |r| format!("#{}", r));
84106
let mut msg = format!(
85-
"check directive(s) from `{}` not found in debugger output. errors:",
86-
self.file
107+
"check directive(s) from `{}{}` not found in debugger output. errors:",
108+
self.file, revision_suffix
87109
);
88110

89111
for (src_lineno, err_line) in missing {
@@ -103,18 +125,6 @@ impl DebuggerCommands {
103125
}
104126
}
105127

106-
/// Split off from the main `parse_name_value_directive`, so that improvements
107-
/// to directive handling aren't held back by debuginfo test commands.
108-
fn parse_name_value(line: &str, name: &str) -> Option<String> {
109-
if let Some(after_name) = line.strip_prefix(name)
110-
&& let Some(value) = after_name.strip_prefix(':')
111-
{
112-
Some(value.to_owned())
113-
} else {
114-
None
115-
}
116-
}
117-
118128
/// Check that the pattern in `check_line` applies to `line`. Returns `true` if they do match.
119129
fn check_single_line(line: &str, check_line: &str) -> bool {
120130
// Allow check lines to leave parts unspecified (e.g., uninitialized

src/tools/compiletest/src/runtest/debuginfo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl TestCx<'_> {
4646
}
4747

4848
// Parse debugger commands etc from test files
49-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb")
49+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "cdb", self.revision)
5050
.unwrap_or_else(|e| self.fatal(&e));
5151

5252
// https://docs.microsoft.com/en-us/windows-hardware/drivers/debugger/debugger-commands
@@ -105,7 +105,7 @@ impl TestCx<'_> {
105105
}
106106

107107
fn run_debuginfo_gdb_test(&self) {
108-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb")
108+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "gdb", self.revision)
109109
.unwrap_or_else(|e| self.fatal(&e));
110110
let mut cmds = dbg_cmds.commands.join("\n");
111111

@@ -366,7 +366,7 @@ impl TestCx<'_> {
366366
}
367367

368368
// Parse debugger commands etc from test files
369-
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb")
369+
let dbg_cmds = DebuggerCommands::parse_from(&self.testpaths.file, "lldb", self.revision)
370370
.unwrap_or_else(|e| self.fatal(&e));
371371

372372
// Write debugger script:

0 commit comments

Comments
 (0)