Skip to content

Commit 5f81d83

Browse files
committed
Auto merge of #2933 - RalfJung:rustup, r=RalfJung
Rustup
2 parents 20a2a24 + 14155e9 commit 5f81d83

File tree

167 files changed

+1875
-1960
lines changed

Some content is hidden

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

167 files changed

+1875
-1960
lines changed

.github/workflows/ci.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ jobs:
3838
env:
3939
CI_JOB_NAME: "${{ matrix.name }}"
4040
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
41+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
4142
SCCACHE_BUCKET: rust-lang-ci-sccache2
4243
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
4344
CACHE_DOMAIN: ci-caches.rust-lang.org
@@ -143,6 +144,17 @@ jobs:
143144
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
144145
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
145146
if: success() && !env.SKIP_JOB
147+
- name: create github artifacts
148+
run: src/ci/scripts/create-doc-artifacts.sh
149+
if: success() && !env.SKIP_JOB
150+
- name: upload artifacts to github
151+
uses: actions/upload-artifact@v3
152+
with:
153+
name: "${{ env.DOC_ARTIFACT_NAME }}"
154+
path: obj/artifacts/doc
155+
if-no-files-found: ignore
156+
retention-days: 5
157+
if: success() && !env.SKIP_JOB
146158
- name: upload artifacts to S3
147159
run: src/ci/scripts/upload-artifacts.sh
148160
env:
@@ -156,6 +168,7 @@ jobs:
156168
env:
157169
CI_JOB_NAME: "${{ matrix.name }}"
158170
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
171+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
159172
SCCACHE_BUCKET: rust-lang-ci-sccache2
160173
DEPLOY_BUCKET: rust-lang-ci2
161174
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -557,6 +570,17 @@ jobs:
557570
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
558571
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
559572
if: success() && !env.SKIP_JOB
573+
- name: create github artifacts
574+
run: src/ci/scripts/create-doc-artifacts.sh
575+
if: success() && !env.SKIP_JOB
576+
- name: upload artifacts to github
577+
uses: actions/upload-artifact@v3
578+
with:
579+
name: "${{ env.DOC_ARTIFACT_NAME }}"
580+
path: obj/artifacts/doc
581+
if-no-files-found: ignore
582+
retention-days: 5
583+
if: success() && !env.SKIP_JOB
560584
- name: upload artifacts to S3
561585
run: src/ci/scripts/upload-artifacts.sh
562586
env:
@@ -571,6 +595,7 @@ jobs:
571595
DIST_TRY_BUILD: 1
572596
CI_JOB_NAME: "${{ matrix.name }}"
573597
CARGO_REGISTRIES_CRATES_IO_PROTOCOL: sparse
598+
HEAD_SHA: "${{ github.event.pull_request.head.sha || github.sha }}"
574599
SCCACHE_BUCKET: rust-lang-ci-sccache2
575600
DEPLOY_BUCKET: rust-lang-ci2
576601
TOOLSTATE_REPO: "https://github.com/rust-lang-nursery/rust-toolstate"
@@ -672,6 +697,17 @@ jobs:
672697
AWS_SECRET_ACCESS_KEY: "${{ secrets[format('AWS_SECRET_ACCESS_KEY_{0}', env.CACHES_AWS_ACCESS_KEY_ID)] }}"
673698
TOOLSTATE_REPO_ACCESS_TOKEN: "${{ secrets.TOOLSTATE_REPO_ACCESS_TOKEN }}"
674699
if: success() && !env.SKIP_JOB
700+
- name: create github artifacts
701+
run: src/ci/scripts/create-doc-artifacts.sh
702+
if: success() && !env.SKIP_JOB
703+
- name: upload artifacts to github
704+
uses: actions/upload-artifact@v3
705+
with:
706+
name: "${{ env.DOC_ARTIFACT_NAME }}"
707+
path: obj/artifacts/doc
708+
if-no-files-found: ignore
709+
retention-days: 5
710+
if: success() && !env.SKIP_JOB
675711
- name: upload artifacts to S3
676712
run: src/ci/scripts/upload-artifacts.sh
677713
env:

compiler/rustc_codegen_gcc/src/common.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
108108
self.const_uint(self.type_u64(), i)
109109
}
110110

111+
fn const_u128(&self, i: u128) -> RValue<'gcc> {
112+
self.const_uint_big(self.type_u128(), i)
113+
}
114+
111115
fn const_usize(&self, i: u64) -> RValue<'gcc> {
112116
let bit_size = self.data_layout().pointer_size.bits();
113117
if bit_size < 64 {
@@ -254,7 +258,7 @@ impl<'gcc, 'tcx> ConstMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
254258
// SIMD builtins require a constant value.
255259
self.bitcast_if_needed(value, typ)
256260
}
257-
261+
258262
fn const_ptr_byte_offset(&self, base_addr: Self::Value, offset: abi::Size) -> Self::Value {
259263
self.context.new_array_access(None, base_addr, self.const_usize(offset.bytes())).get_address(None)
260264
}

compiler/rustc_codegen_llvm/src/common.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ impl<'ll, 'tcx> ConstMethods<'tcx> for CodegenCx<'ll, 'tcx> {
168168
self.const_uint(self.type_i64(), i)
169169
}
170170

171+
fn const_u128(&self, i: u128) -> &'ll Value {
172+
self.const_uint_big(self.type_i128(), i)
173+
}
174+
171175
fn const_usize(&self, i: u64) -> &'ll Value {
172176
let bit_size = self.data_layout().pointer_size.bits();
173177
if bit_size < 64 {

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
429429
return existing_di_node;
430430
}
431431

432-
debug!("type_di_node: {:?}", t);
432+
debug!("type_di_node: {:?} kind: {:?}", t, t.kind());
433433

434434
let DINodeCreationResult { di_node, already_stored_in_typemap } = match *t.kind() {
435435
ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,7 @@ fn build_enum_variant_member_di_node<'ll, 'tcx>(
412412
enum_type_and_layout.size.bits(),
413413
enum_type_and_layout.align.abi.bits() as u32,
414414
Size::ZERO.bits(),
415-
discr_value.opt_single_val().map(|value| {
416-
// NOTE(eddyb) do *NOT* remove this assert, until
417-
// we pass the full 128-bit value to LLVM, otherwise
418-
// truncation will be silent and remain undetected.
419-
assert_eq!(value as u64 as u128, value);
420-
cx.const_u64(value as u64)
421-
}),
415+
discr_value.opt_single_val().map(|value| cx.const_u128(value)),
422416
DIFlags::FlagZero,
423417
variant_member_info.variant_struct_type_di_node,
424418
)

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_data_structures::fx::FxIndexMap;
55
use rustc_data_structures::memmap::Mmap;
66
use rustc_data_structures::temp_dir::MaybeTempDir;
77
use rustc_errors::{ErrorGuaranteed, Handler};
8-
use rustc_fs_util::fix_windows_verbatim_for_gcc;
8+
use rustc_fs_util::{fix_windows_verbatim_for_gcc, try_canonicalize};
99
use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
1010
use rustc_metadata::find_native_static_library;
1111
use rustc_metadata::fs::{copy_to_stdout, emit_wrapper_file, METADATA_FILENAME};
@@ -2682,6 +2682,30 @@ fn add_upstream_native_libraries(
26822682
}
26832683
}
26842684

2685+
// Rehome lib paths (which exclude the library file name) that point into the sysroot lib directory
2686+
// to be relative to the sysroot directory, which may be a relative path specified by the user.
2687+
//
2688+
// If the sysroot is a relative path, and the sysroot libs are specified as an absolute path, the
2689+
// linker command line can be non-deterministic due to the paths including the current working
2690+
// directory. The linker command line needs to be deterministic since it appears inside the PDB
2691+
// file generated by the MSVC linker. See https://github.com/rust-lang/rust/issues/112586.
2692+
//
2693+
// The returned path will always have `fix_windows_verbatim_for_gcc()` applied to it.
2694+
fn rehome_sysroot_lib_dir<'a>(sess: &'a Session, lib_dir: &Path) -> PathBuf {
2695+
let sysroot_lib_path = sess.target_filesearch(PathKind::All).get_lib_path();
2696+
let canonical_sysroot_lib_path =
2697+
{ try_canonicalize(&sysroot_lib_path).unwrap_or_else(|_| sysroot_lib_path.clone()) };
2698+
2699+
let canonical_lib_dir = try_canonicalize(lib_dir).unwrap_or_else(|_| lib_dir.to_path_buf());
2700+
if canonical_lib_dir == canonical_sysroot_lib_path {
2701+
// This path, returned by `target_filesearch().get_lib_path()`, has
2702+
// already had `fix_windows_verbatim_for_gcc()` applied if needed.
2703+
sysroot_lib_path
2704+
} else {
2705+
fix_windows_verbatim_for_gcc(&lib_dir)
2706+
}
2707+
}
2708+
26852709
// Adds the static "rlib" versions of all crates to the command line.
26862710
// There's a bit of magic which happens here specifically related to LTO,
26872711
// namely that we remove upstream object files.
@@ -2713,7 +2737,13 @@ fn add_static_crate<'a>(
27132737
let cratepath = &src.rlib.as_ref().unwrap().0;
27142738

27152739
let mut link_upstream = |path: &Path| {
2716-
cmd.link_rlib(&fix_windows_verbatim_for_gcc(path));
2740+
let rlib_path = if let Some(dir) = path.parent() {
2741+
let file_name = path.file_name().expect("rlib path has no file name path component");
2742+
rehome_sysroot_lib_dir(sess, &dir).join(file_name)
2743+
} else {
2744+
fix_windows_verbatim_for_gcc(path)
2745+
};
2746+
cmd.link_rlib(&rlib_path);
27172747
};
27182748

27192749
if !are_upstream_rust_objects_already_included(sess)
@@ -2782,7 +2812,7 @@ fn add_dynamic_crate(cmd: &mut dyn Linker, sess: &Session, cratepath: &Path) {
27822812
// what its name is
27832813
let parent = cratepath.parent();
27842814
if let Some(dir) = parent {
2785-
cmd.include_path(&fix_windows_verbatim_for_gcc(dir));
2815+
cmd.include_path(&rehome_sysroot_lib_dir(sess, dir));
27862816
}
27872817
let stem = cratepath.file_stem().unwrap().to_str().unwrap();
27882818
// Convert library file-stem into a cc -l argument.

compiler/rustc_codegen_ssa/src/traits/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub trait ConstMethods<'tcx>: BackendTypes {
1515
fn const_i32(&self, i: i32) -> Self::Value;
1616
fn const_u32(&self, i: u32) -> Self::Value;
1717
fn const_u64(&self, i: u64) -> Self::Value;
18+
fn const_u128(&self, i: u128) -> Self::Value;
1819
fn const_usize(&self, i: u64) -> Self::Value;
1920
fn const_u8(&self, i: u8) -> Self::Value;
2021
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;

compiler/rustc_const_eval/src/transform/check_consts/check.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,17 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
781781
);
782782
return;
783783
}
784-
Ok(Some(ImplSource::Closure(data))) => {
785-
if !tcx.is_const_fn_raw(data.closure_def_id) {
784+
// Closure: Fn{Once|Mut}
785+
Ok(Some(ImplSource::Builtin(_)))
786+
if poly_trait_pred.self_ty().skip_binder().is_closure()
787+
&& tcx.fn_trait_kind_from_def_id(trait_id).is_some() =>
788+
{
789+
let ty::Closure(closure_def_id, substs) =
790+
*poly_trait_pred.self_ty().no_bound_vars().unwrap().kind()
791+
else {
792+
unreachable!()
793+
};
794+
if !tcx.is_const_fn_raw(closure_def_id) {
786795
self.check_op(ops::FnCallNonConst {
787796
caller,
788797
callee,

compiler/rustc_const_eval/src/transform/check_consts/qualifs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl Qualif for NeedsNonConstDrop {
172172

173173
if !matches!(
174174
impl_src,
175-
ImplSource::ConstDestruct(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
175+
ImplSource::Builtin(_) | ImplSource::Param(_, ty::BoundConstness::ConstIfConst)
176176
) {
177177
// If our const destruct candidate is not ConstDestruct or implied by the param env,
178178
// then it's bad

compiler/rustc_const_eval/src/util/type_name.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
6363
| ty::Generator(def_id, substs, _) => self.print_def_path(def_id, substs),
6464
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),
6565

66+
ty::Alias(ty::Weak, _) => bug!("type_name: unexpected weak projection"),
6667
ty::Alias(ty::Inherent, _) => bug!("type_name: unexpected inherent projection"),
6768
ty::GeneratorWitness(_) => bug!("type_name: unexpected `GeneratorWitness`"),
6869
ty::GeneratorWitnessMIR(..) => bug!("type_name: unexpected `GeneratorWitnessMIR`"),

compiler/rustc_expand/src/mbe/quoted.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_session::parse::{feature_err, ParseSess};
99
use rustc_span::symbol::{kw, sym, Ident};
1010

1111
use rustc_span::edition::Edition;
12-
use rustc_span::{Span, SyntaxContext};
12+
use rustc_span::Span;
1313

1414
const VALID_FRAGMENT_NAMES_MSG: &str = "valid fragment specifiers are \
1515
`ident`, `block`, `stmt`, `expr`, `pat`, `ty`, `lifetime`, \
@@ -72,7 +72,7 @@ pub(super) fn parse(
7272
// `SyntaxContext::root()` from a foreign crate will
7373
// have the edition of that crate (which we manually
7474
// retrieve via the `edition` parameter).
75-
if span.ctxt() == SyntaxContext::root() {
75+
if span.ctxt().is_root() {
7676
edition
7777
} else {
7878
span.edition()

compiler/rustc_hir/src/lang_items.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,8 @@ language_item_table! {
260260
EhCatchTypeinfo, sym::eh_catch_typeinfo, eh_catch_typeinfo, Target::Static, GenericRequirement::None;
261261

262262
OwnedBox, sym::owned_box, owned_box, Target::Struct, GenericRequirement::Minimum(1);
263+
// Experimental language item for Miri
264+
PtrUnique, sym::ptr_unique, ptr_unique, Target::Struct, GenericRequirement::Exact(1);
263265

264266
PhantomData, sym::phantom_data, phantom_data, Target::Struct, GenericRequirement::Exact(1);
265267

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
use rustc_ast::TraitObjectSyntax;
2+
use rustc_errors::{Diagnostic, StashKey};
3+
use rustc_hir as hir;
4+
use rustc_lint_defs::{builtin::BARE_TRAIT_OBJECTS, Applicability};
5+
use rustc_trait_selection::traits::error_reporting::suggestions::NextTypeParamName;
6+
7+
use super::AstConv;
8+
9+
impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10+
/// Make sure that we are in the condition to suggest the blanket implementation.
11+
pub(super) fn maybe_lint_blanket_trait_impl(
12+
&self,
13+
self_ty: &hir::Ty<'_>,
14+
diag: &mut Diagnostic,
15+
) {
16+
let tcx = self.tcx();
17+
let parent_id = tcx.hir().get_parent_item(self_ty.hir_id).def_id;
18+
if let hir::Node::Item(hir::Item {
19+
kind:
20+
hir::ItemKind::Impl(hir::Impl {
21+
self_ty: impl_self_ty, of_trait: Some(of_trait_ref), generics, ..
22+
}),
23+
..
24+
}) = tcx.hir().get_by_def_id(parent_id) && self_ty.hir_id == impl_self_ty.hir_id
25+
{
26+
if !of_trait_ref.trait_def_id().is_some_and(|def_id| def_id.is_local()) {
27+
return;
28+
}
29+
let of_trait_span = of_trait_ref.path.span;
30+
// make sure that we are not calling unwrap to abort during the compilation
31+
let Ok(impl_trait_name) = tcx.sess.source_map().span_to_snippet(self_ty.span) else { return; };
32+
let Ok(of_trait_name) = tcx.sess.source_map().span_to_snippet(of_trait_span) else { return; };
33+
// check if the trait has generics, to make a correct suggestion
34+
let param_name = generics.params.next_type_param_name(None);
35+
36+
let add_generic_sugg = if let Some(span) = generics.span_for_param_suggestion() {
37+
(span, format!(", {}: {}", param_name, impl_trait_name))
38+
} else {
39+
(generics.span, format!("<{}: {}>", param_name, impl_trait_name))
40+
};
41+
diag.multipart_suggestion(
42+
format!("alternatively use a blanket \
43+
implementation to implement `{of_trait_name}` for \
44+
all types that also implement `{impl_trait_name}`"),
45+
vec![
46+
(self_ty.span, param_name),
47+
add_generic_sugg,
48+
],
49+
Applicability::MaybeIncorrect,
50+
);
51+
}
52+
}
53+
54+
pub(super) fn maybe_lint_bare_trait(&self, self_ty: &hir::Ty<'_>, in_path: bool) {
55+
let tcx = self.tcx();
56+
if let hir::TyKind::TraitObject([poly_trait_ref, ..], _, TraitObjectSyntax::None) =
57+
self_ty.kind
58+
{
59+
let needs_bracket = in_path
60+
&& !tcx
61+
.sess
62+
.source_map()
63+
.span_to_prev_source(self_ty.span)
64+
.ok()
65+
.is_some_and(|s| s.trim_end().ends_with('<'));
66+
67+
let is_global = poly_trait_ref.trait_ref.path.is_global();
68+
69+
let mut sugg = Vec::from_iter([(
70+
self_ty.span.shrink_to_lo(),
71+
format!(
72+
"{}dyn {}",
73+
if needs_bracket { "<" } else { "" },
74+
if is_global { "(" } else { "" },
75+
),
76+
)]);
77+
78+
if is_global || needs_bracket {
79+
sugg.push((
80+
self_ty.span.shrink_to_hi(),
81+
format!(
82+
"{}{}",
83+
if is_global { ")" } else { "" },
84+
if needs_bracket { ">" } else { "" },
85+
),
86+
));
87+
}
88+
89+
if self_ty.span.edition().rust_2021() {
90+
let msg = "trait objects must include the `dyn` keyword";
91+
let label = "add `dyn` keyword before this trait";
92+
let mut diag =
93+
rustc_errors::struct_span_err!(tcx.sess, self_ty.span, E0782, "{}", msg);
94+
if self_ty.span.can_be_used_for_suggestions() {
95+
diag.multipart_suggestion_verbose(
96+
label,
97+
sugg,
98+
Applicability::MachineApplicable,
99+
);
100+
}
101+
// check if the impl trait that we are considering is a impl of a local trait
102+
self.maybe_lint_blanket_trait_impl(&self_ty, &mut diag);
103+
diag.stash(self_ty.span, StashKey::TraitMissingMethod);
104+
} else {
105+
let msg = "trait objects without an explicit `dyn` are deprecated";
106+
tcx.struct_span_lint_hir(
107+
BARE_TRAIT_OBJECTS,
108+
self_ty.hir_id,
109+
self_ty.span,
110+
msg,
111+
|lint| {
112+
lint.multipart_suggestion_verbose(
113+
"use `dyn`",
114+
sugg,
115+
Applicability::MachineApplicable,
116+
);
117+
self.maybe_lint_blanket_trait_impl(&self_ty, lint);
118+
lint
119+
},
120+
);
121+
}
122+
}
123+
}
124+
}

0 commit comments

Comments
 (0)