Skip to content

Commit 6eb9f2d

Browse files
committed
Auto merge of #107788 - matthiaskrgr:rollup-mw10sli, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #107656 (Bump rust-installer) - #107757 (Allow automatically creating vscode `settings.json` with `x setup`) - #107769 (Rename `PointerSized` to `PointerLike`) - #107770 (rustdoc: use a newline instead of `<br>` to format code headers) - #107771 (Tweak ICE message) - #107773 (Clearly signal purpose of the yaml template) - #107776 (Docs: Fix format of headings in String::reserve) - #107779 (Remove astconv usage in diagnostic) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7ba4e95 + fe26182 commit 6eb9f2d

Some content is hidden

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

53 files changed

+375
-165
lines changed

.github/ISSUE_TEMPLATE/ice.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Internal Compiler Error (Structured form)
1+
name: Internal Compiler Error (for use by automated tooling)
22
description: For now, you'll want to use the other ICE template, as GitHub forms have strict limits on the size of fields so backtraces cannot be pasted directly.
33
labels: ["C-bug", "I-ICE", "T-compiler"]
44
title: "[ICE]: "

compiler/rustc_const_eval/src/interpret/cast.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
126126
let vtable = self.get_vtable_ptr(src.layout.ty, data.principal())?;
127127
let vtable = Scalar::from_maybe_pointer(vtable, self);
128128
let data = self.read_immediate(src)?.to_scalar();
129-
let _assert_pointer_sized = data.to_pointer(self)?;
129+
let _assert_pointer_like = data.to_pointer(self)?;
130130
let val = Immediate::ScalarPair(data, vtable);
131131
self.write_immediate(val, dest)?;
132132
} else {

compiler/rustc_driver_impl/src/lib.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1200,11 +1200,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12001200
if !info.payload().is::<rustc_errors::ExplicitBug>()
12011201
&& !info.payload().is::<rustc_errors::DelayedBugPanic>()
12021202
{
1203-
let mut d = rustc_errors::Diagnostic::new(rustc_errors::Level::Bug, "unexpected panic");
1204-
handler.emit_diagnostic(&mut d);
1203+
handler.emit_err(session_diagnostics::Ice);
12051204
}
12061205

1207-
handler.emit_note(session_diagnostics::Ice);
12081206
handler.emit_note(session_diagnostics::IceBugReport { bug_report_url });
12091207
handler.emit_note(session_diagnostics::IceVersion {
12101208
version: util::version_str!().unwrap_or("unknown_version"),

compiler/rustc_hir/src/lang_items.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ language_item_table! {
287287
TryTraitBranch, sym::branch, branch_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;
288288
TryTraitFromYeet, sym::from_yeet, from_yeet_fn, Target::Fn, GenericRequirement::None;
289289

290-
PointerSized, sym::pointer_sized, pointer_sized, Target::Trait, GenericRequirement::Exact(0);
290+
PointerLike, sym::pointer_like, pointer_like, Target::Trait, GenericRequirement::Exact(0);
291291

292292
Poll, sym::Poll, poll, Target::Enum, GenericRequirement::None;
293293
PollReady, sym::Ready, poll_ready_variant, Target::Variant, GenericRequirement::None;

compiler/rustc_hir_typeck/src/coercion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -765,7 +765,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
765765
self.cause.clone(),
766766
self.param_env,
767767
ty::Binder::dummy(
768-
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerSized, [a]),
768+
self.tcx.at(self.cause.span).mk_trait_ref(hir::LangItem::PointerLike, [a]),
769769
),
770770
));
771771

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+11-10
Original file line numberDiff line numberDiff line change
@@ -1336,16 +1336,17 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
13361336
hir::Path { segments: [segment], .. },
13371337
))
13381338
| hir::ExprKind::Path(QPath::TypeRelative(ty, segment)) => {
1339-
let self_ty = self.astconv().ast_ty_to_ty(ty);
1340-
if let Ok(pick) = self.probe_for_name(
1341-
Mode::Path,
1342-
Ident::new(capitalized_name, segment.ident.span),
1343-
Some(expected_ty),
1344-
IsSuggestion(true),
1345-
self_ty,
1346-
expr.hir_id,
1347-
ProbeScope::TraitsInScope,
1348-
) {
1339+
if let Some(self_ty) = self.typeck_results.borrow().node_type_opt(ty.hir_id)
1340+
&& let Ok(pick) = self.probe_for_name(
1341+
Mode::Path,
1342+
Ident::new(capitalized_name, segment.ident.span),
1343+
Some(expected_ty),
1344+
IsSuggestion(true),
1345+
self_ty,
1346+
expr.hir_id,
1347+
ProbeScope::TraitsInScope,
1348+
)
1349+
{
13491350
(pick.item, segment)
13501351
} else {
13511352
return false;

compiler/rustc_span/src/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1084,7 +1084,7 @@ symbols! {
10841084
plugins,
10851085
pointee_trait,
10861086
pointer,
1087-
pointer_sized,
1087+
pointer_like,
10881088
poll,
10891089
position,
10901090
post_dash_lto: "post-lto",

compiler/rustc_trait_selection/src/solve/assembly.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,9 @@ pub(super) trait GoalKind<'tcx>: TypeFoldable<'tcx> + Copy + Eq {
128128
goal: Goal<'tcx, Self>,
129129
) -> QueryResult<'tcx>;
130130

131-
// A type is `PointerSized` if we can compute its layout, and that layout
131+
// A type is `PointerLike` if we can compute its layout, and that layout
132132
// matches the layout of `usize`.
133-
fn consider_builtin_pointer_sized_candidate(
133+
fn consider_builtin_pointer_like_candidate(
134134
ecx: &mut EvalCtxt<'_, 'tcx>,
135135
goal: Goal<'tcx, Self>,
136136
) -> QueryResult<'tcx>;
@@ -312,8 +312,8 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
312312
|| lang_items.clone_trait() == Some(trait_def_id)
313313
{
314314
G::consider_builtin_copy_clone_candidate(self, goal)
315-
} else if lang_items.pointer_sized() == Some(trait_def_id) {
316-
G::consider_builtin_pointer_sized_candidate(self, goal)
315+
} else if lang_items.pointer_like() == Some(trait_def_id) {
316+
G::consider_builtin_pointer_like_candidate(self, goal)
317317
} else if let Some(kind) = self.tcx().fn_trait_kind_from_def_id(trait_def_id) {
318318
G::consider_builtin_fn_trait_candidates(self, goal, kind)
319319
} else if lang_items.tuple_trait() == Some(trait_def_id) {

compiler/rustc_trait_selection/src/solve/project_goals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -370,11 +370,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
370370
bug!("`Copy`/`Clone` does not have an associated type: {:?}", goal);
371371
}
372372

373-
fn consider_builtin_pointer_sized_candidate(
373+
fn consider_builtin_pointer_like_candidate(
374374
_ecx: &mut EvalCtxt<'_, 'tcx>,
375375
goal: Goal<'tcx, Self>,
376376
) -> QueryResult<'tcx> {
377-
bug!("`PointerSized` does not have an associated type: {:?}", goal);
377+
bug!("`PointerLike` does not have an associated type: {:?}", goal);
378378
}
379379

380380
fn consider_builtin_fn_trait_candidates(

compiler/rustc_trait_selection/src/solve/trait_goals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
131131
)
132132
}
133133

134-
fn consider_builtin_pointer_sized_candidate(
134+
fn consider_builtin_pointer_like_candidate(
135135
ecx: &mut EvalCtxt<'_, 'tcx>,
136136
goal: Goal<'tcx, Self>,
137137
) -> QueryResult<'tcx> {

compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
9494
self.assemble_candidates_for_transmutability(obligation, &mut candidates);
9595
} else if lang_items.tuple_trait() == Some(def_id) {
9696
self.assemble_candidate_for_tuple(obligation, &mut candidates);
97-
} else if lang_items.pointer_sized() == Some(def_id) {
97+
} else if lang_items.pointer_like() == Some(def_id) {
9898
self.assemble_candidate_for_ptr_sized(obligation, &mut candidates);
9999
} else {
100100
if lang_items.clone_trait() == Some(def_id) {

library/alloc/src/string.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -928,12 +928,12 @@ impl String {
928928

929929
/// Copies elements from `src` range to the end of the string.
930930
///
931-
/// ## Panics
931+
/// # Panics
932932
///
933933
/// Panics if the starting point or end point do not lie on a [`char`]
934934
/// boundary, or if they're out of bounds.
935935
///
936-
/// ## Examples
936+
/// # Examples
937937
///
938938
/// ```
939939
/// #![feature(string_extend_from_within)]

library/core/src/marker.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -872,13 +872,14 @@ pub trait Destruct {}
872872
pub trait Tuple {}
873873

874874
/// A marker for things
875-
#[unstable(feature = "pointer_sized_trait", issue = "none")]
876-
#[lang = "pointer_sized"]
875+
#[unstable(feature = "pointer_like_trait", issue = "none")]
876+
#[cfg_attr(bootstrap, lang = "pointer_sized")]
877+
#[cfg_attr(not(bootstrap), lang = "pointer_like")]
877878
#[rustc_on_unimplemented(
878-
message = "`{Self}` needs to be a pointer-sized type",
879-
label = "`{Self}` needs to be a pointer-sized type"
879+
message = "`{Self}` needs to have the same alignment and size as a pointer",
880+
label = "`{Self}` needs to be a pointer-like type"
880881
)]
881-
pub trait PointerSized {}
882+
pub trait PointerLike {}
882883

883884
/// Implementations of `Copy` for primitive types.
884885
///

src/bootstrap/setup.rs

+121-26
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::builder::{Builder, RunConfig, ShouldRun, Step};
22
use crate::Config;
33
use crate::{t, VERSION};
4+
use sha2::Digest;
45
use std::env::consts::EXE_SUFFIX;
56
use std::fmt::Write as _;
67
use std::fs::File;
@@ -10,6 +11,9 @@ use std::process::Command;
1011
use std::str::FromStr;
1112
use std::{fmt, fs, io};
1213

14+
#[cfg(test)]
15+
mod tests;
16+
1317
#[derive(Clone, Copy, Debug, Eq, PartialEq, Hash)]
1418
pub enum Profile {
1519
Compiler,
@@ -19,6 +23,13 @@ pub enum Profile {
1923
User,
2024
}
2125

26+
/// A list of historical hashes of `src/etc/vscode_settings.json`.
27+
/// New entries should be appended whenever this is updated so we can detected
28+
/// outdated vs. user-modified settings files.
29+
static SETTINGS_HASHES: &[&str] =
30+
&["ea67e259dedf60d4429b6c349a564ffcd1563cf41c920a856d1f5b16b4701ac8"];
31+
static VSCODE_SETTINGS: &str = include_str!("../etc/vscode_settings.json");
32+
2233
impl Profile {
2334
fn include_path(&self, src_path: &Path) -> PathBuf {
2435
PathBuf::from(format!("{}/src/bootstrap/defaults/config.{}.toml", src_path.display(), self))
@@ -155,6 +166,7 @@ pub fn setup(config: &Config, profile: Profile) {
155166

156167
if !config.dry_run() {
157168
t!(install_git_hook_maybe(&config));
169+
t!(create_vscode_settings_maybe(&config));
158170
}
159171

160172
println!();
@@ -351,6 +363,34 @@ pub fn interactive_path() -> io::Result<Profile> {
351363
Ok(template)
352364
}
353365

366+
#[derive(PartialEq)]
367+
enum PromptResult {
368+
Yes, // y/Y/yes
369+
No, // n/N/no
370+
Print, // p/P/print
371+
}
372+
373+
/// Prompt a user for a answer, looping until they enter an accepted input or nothing
374+
fn prompt_user(prompt: &str) -> io::Result<Option<PromptResult>> {
375+
let mut input = String::new();
376+
loop {
377+
print!("{prompt} ");
378+
io::stdout().flush()?;
379+
input.clear();
380+
io::stdin().read_line(&mut input)?;
381+
match input.trim().to_lowercase().as_str() {
382+
"y" | "yes" => return Ok(Some(PromptResult::Yes)),
383+
"n" | "no" => return Ok(Some(PromptResult::No)),
384+
"p" | "print" => return Ok(Some(PromptResult::Print)),
385+
"" => return Ok(None),
386+
_ => {
387+
eprintln!("error: unrecognized option '{}'", input.trim());
388+
eprintln!("note: press Ctrl+C to exit");
389+
}
390+
};
391+
}
392+
}
393+
354394
// install a git hook to automatically run tidy, if they want
355395
fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
356396
let git = t!(config.git().args(&["rev-parse", "--git-common-dir"]).output().map(|output| {
@@ -363,43 +403,98 @@ fn install_git_hook_maybe(config: &Config) -> io::Result<()> {
363403
return Ok(());
364404
}
365405

366-
let mut input = String::new();
367-
println!();
368406
println!(
369-
"Rust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
407+
"\nRust's CI will automatically fail if it doesn't pass `tidy`, the internal tool for ensuring code quality.
370408
If you'd like, x.py can install a git hook for you that will automatically run `test tidy` before
371409
pushing your code to ensure your code is up to par. If you decide later that this behavior is
372410
undesirable, simply delete the `pre-push` file from .git/hooks."
373411
);
374412

375-
let should_install = loop {
376-
print!("Would you like to install the git hook?: [y/N] ");
377-
io::stdout().flush()?;
378-
input.clear();
379-
io::stdin().read_line(&mut input)?;
380-
break match input.trim().to_lowercase().as_str() {
381-
"y" | "yes" => true,
382-
"n" | "no" | "" => false,
383-
_ => {
384-
eprintln!("error: unrecognized option '{}'", input.trim());
385-
eprintln!("note: press Ctrl+C to exit");
386-
continue;
387-
}
388-
};
389-
};
390-
391-
if should_install {
392-
let src = config.src.join("src").join("etc").join("pre-push.sh");
393-
match fs::hard_link(src, &dst) {
394-
Err(e) => eprintln!(
413+
if prompt_user("Would you like to install the git hook?: [y/N]")? != Some(PromptResult::Yes) {
414+
println!("Ok, skipping installation!");
415+
return Ok(());
416+
}
417+
let src = config.src.join("src").join("etc").join("pre-push.sh");
418+
match fs::hard_link(src, &dst) {
419+
Err(e) => {
420+
eprintln!(
395421
"error: could not create hook {}: do you already have the git hook installed?\n{}",
396422
dst.display(),
397423
e
398-
),
399-
Ok(_) => println!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
424+
);
425+
return Err(e);
426+
}
427+
Ok(_) => println!("Linked `src/etc/pre-push.sh` to `.git/hooks/pre-push`"),
428+
};
429+
Ok(())
430+
}
431+
432+
/// Create a `.vscode/settings.json` file for rustc development, or just print it
433+
fn create_vscode_settings_maybe(config: &Config) -> io::Result<()> {
434+
let (current_hash, historical_hashes) = SETTINGS_HASHES.split_last().unwrap();
435+
let vscode_settings = config.src.join(".vscode").join("settings.json");
436+
// If None, no settings.json exists
437+
// If Some(true), is a previous version of settings.json
438+
// If Some(false), is not a previous version (i.e. user modified)
439+
// If it's up to date we can just skip this
440+
let mut mismatched_settings = None;
441+
if let Ok(current) = fs::read_to_string(&vscode_settings) {
442+
let mut hasher = sha2::Sha256::new();
443+
hasher.update(&current);
444+
let hash = hex::encode(hasher.finalize().as_slice());
445+
if hash == *current_hash {
446+
return Ok(());
447+
} else if historical_hashes.contains(&hash.as_str()) {
448+
mismatched_settings = Some(true);
449+
} else {
450+
mismatched_settings = Some(false);
451+
}
452+
}
453+
println!(
454+
"\nx.py can automatically install the recommended `.vscode/settings.json` file for rustc development"
455+
);
456+
match mismatched_settings {
457+
Some(true) => eprintln!(
458+
"warning: existing `.vscode/settings.json` is out of date, x.py will update it"
459+
),
460+
Some(false) => eprintln!(
461+
"warning: existing `.vscode/settings.json` has been modified by user, x.py will back it up and replace it"
462+
),
463+
_ => (),
464+
}
465+
let should_create = match prompt_user(
466+
"Would you like to create/update `settings.json`, or only print suggested settings?: [y/p/N]",
467+
)? {
468+
Some(PromptResult::Yes) => true,
469+
Some(PromptResult::Print) => false,
470+
_ => {
471+
println!("Ok, skipping settings!");
472+
return Ok(());
473+
}
474+
};
475+
if should_create {
476+
let path = config.src.join(".vscode");
477+
if !path.exists() {
478+
fs::create_dir(&path)?;
479+
}
480+
let verb = match mismatched_settings {
481+
// exists but outdated, we can replace this
482+
Some(true) => "Updated",
483+
// exists but user modified, back it up
484+
Some(false) => {
485+
// exists and is not current version or outdated, so back it up
486+
let mut backup = vscode_settings.clone();
487+
backup.set_extension("bak");
488+
eprintln!("warning: copying `settings.json` to `settings.json.bak`");
489+
fs::copy(&vscode_settings, &backup)?;
490+
"Updated"
491+
}
492+
_ => "Created",
400493
};
494+
fs::write(&vscode_settings, &VSCODE_SETTINGS)?;
495+
println!("{verb} `.vscode/settings.json`");
401496
} else {
402-
println!("Ok, skipping installation!");
497+
println!("\n{VSCODE_SETTINGS}");
403498
}
404499
Ok(())
405500
}

src/bootstrap/setup/tests.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use super::{SETTINGS_HASHES, VSCODE_SETTINGS};
2+
use sha2::Digest;
3+
4+
#[test]
5+
fn check_matching_settings_hash() {
6+
let mut hasher = sha2::Sha256::new();
7+
hasher.update(&VSCODE_SETTINGS);
8+
let hash = hex::encode(hasher.finalize().as_slice());
9+
assert_eq!(
10+
&hash,
11+
SETTINGS_HASHES.last().unwrap(),
12+
"Update `SETTINGS_HASHES` with the new hash of `src/etc/vscode_settings.json`"
13+
);
14+
}

0 commit comments

Comments
 (0)