Skip to content

Commit e704e95

Browse files
committed
Auto merge of #104877 - matthiaskrgr:rollup-s7taiq8, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #103648 (Don't set `is_preview` for clippy and rustfmt) - #104654 (Add `#![deny(unsafe_op_in_unsafe_fn)]` in liballoc tests) - #104793 (unstable-book: Add page for the `abi_efiapi` feature) - #104841 (Assert that we don't capture escaping bound vars in `Fn` trait selection) - #104849 (Migrate source code elements style to CSS variables) - #104873 (RefCell::get_mut: fix typo) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 8a75c5a + f360686 commit e704e95

File tree

19 files changed

+144
-69
lines changed

19 files changed

+144
-69
lines changed

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

+13-16
Original file line numberDiff line numberDiff line change
@@ -605,8 +605,10 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
605605
{
606606
debug!(?obligation, "confirm_fn_pointer_candidate");
607607

608-
// Okay to skip binder; it is reintroduced below.
609-
let self_ty = self.infcx.shallow_resolve(obligation.self_ty().skip_binder());
608+
let self_ty = self
609+
.infcx
610+
.shallow_resolve(obligation.self_ty().no_bound_vars())
611+
.expect("fn pointer should not capture bound vars from predicate");
610612
let sig = self_ty.fn_sig(self.tcx());
611613
let trait_ref = closure_trait_ref_and_return_type(
612614
self.tcx(),
@@ -621,15 +623,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
621623

622624
// Confirm the `type Output: Sized;` bound that is present on `FnOnce`
623625
let cause = obligation.derived_cause(BuiltinDerivedObligation);
624-
// The binder on the Fn obligation is "less" important than the one on
625-
// the signature, as evidenced by how we treat it during projection.
626-
// The safe thing to do here is to liberate it, though, which should
627-
// have no worse effect than skipping the binder here.
628-
let liberated_fn_ty =
629-
self.infcx.replace_bound_vars_with_placeholders(obligation.predicate.rebind(self_ty));
630-
let output_ty = self
631-
.infcx
632-
.replace_bound_vars_with_placeholders(liberated_fn_ty.fn_sig(self.tcx()).output());
626+
let output_ty = self.infcx.replace_bound_vars_with_placeholders(sig.output());
633627
let output_ty = normalize_with_depth_to(
634628
self,
635629
obligation.param_env,
@@ -693,16 +687,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
693687

694688
let gen_sig = substs.as_generator().poly_sig();
695689

696-
// (1) Feels icky to skip the binder here, but OTOH we know
697-
// that the self-type is an generator type and hence is
690+
// NOTE: The self-type is a generator type and hence is
698691
// in fact unparameterized (or at least does not reference any
699-
// regions bound in the obligation). Still probably some
700-
// refactoring could make this nicer.
692+
// regions bound in the obligation).
693+
let self_ty = obligation
694+
.predicate
695+
.self_ty()
696+
.no_bound_vars()
697+
.expect("unboxed closure type should not capture bound vars from the predicate");
701698

702699
let trait_ref = super::util::generator_trait_ref_and_outputs(
703700
self.tcx(),
704701
obligation.predicate.def_id(),
705-
obligation.predicate.skip_binder().self_ty(), // (1)
702+
self_ty,
706703
gen_sig,
707704
)
708705
.map_bound(|(trait_ref, ..)| trait_ref);

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -2271,15 +2271,19 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
22712271

22722272
debug!(?closure_sig);
22732273

2274-
// (1) Feels icky to skip the binder here, but OTOH we know
2275-
// that the self-type is an unboxed closure type and hence is
2274+
// NOTE: The self-type is an unboxed closure type and hence is
22762275
// in fact unparameterized (or at least does not reference any
2277-
// regions bound in the obligation). Still probably some
2278-
// refactoring could make this nicer.
2276+
// regions bound in the obligation).
2277+
let self_ty = obligation
2278+
.predicate
2279+
.self_ty()
2280+
.no_bound_vars()
2281+
.expect("unboxed closure type should not capture bound vars from the predicate");
2282+
22792283
closure_trait_ref_and_return_type(
22802284
self.tcx(),
22812285
obligation.predicate.def_id(),
2282-
obligation.predicate.skip_binder().self_ty(), // (1)
2286+
self_ty,
22832287
closure_sig,
22842288
util::TupleArgumentsFlag::No,
22852289
)

compiler/rustc_trait_selection/src/traits/util.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,11 @@ pub fn closure_trait_ref_and_return_type<'tcx>(
298298
sig: ty::PolyFnSig<'tcx>,
299299
tuple_arguments: TupleArgumentsFlag,
300300
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> {
301+
assert!(!self_ty.has_escaping_bound_vars());
301302
let arguments_tuple = match tuple_arguments {
302303
TupleArgumentsFlag::No => sig.skip_binder().inputs()[0],
303304
TupleArgumentsFlag::Yes => tcx.intern_tup(sig.skip_binder().inputs()),
304305
};
305-
debug_assert!(!self_ty.has_escaping_bound_vars());
306306
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]);
307307
sig.map_bound(|sig| (trait_ref, sig.output()))
308308
}
@@ -313,7 +313,7 @@ pub fn generator_trait_ref_and_outputs<'tcx>(
313313
self_ty: Ty<'tcx>,
314314
sig: ty::PolyGenSig<'tcx>,
315315
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>, Ty<'tcx>)> {
316-
debug_assert!(!self_ty.has_escaping_bound_vars());
316+
assert!(!self_ty.has_escaping_bound_vars());
317317
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, sig.skip_binder().resume_ty]);
318318
sig.map_bound(|sig| (trait_ref, sig.yield_ty, sig.return_ty))
319319
}
@@ -324,7 +324,7 @@ pub fn future_trait_ref_and_outputs<'tcx>(
324324
self_ty: Ty<'tcx>,
325325
sig: ty::PolyGenSig<'tcx>,
326326
) -> ty::Binder<'tcx, (ty::TraitRef<'tcx>, Ty<'tcx>)> {
327-
debug_assert!(!self_ty.has_escaping_bound_vars());
327+
assert!(!self_ty.has_escaping_bound_vars());
328328
let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty]);
329329
sig.map_bound(|sig| (trait_ref, sig.return_ty))
330330
}

library/alloc/tests/boxed.rs

+35-6
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,18 @@ unsafe impl const Allocator for ConstAllocator {
102102

103103
let new_ptr = self.allocate(new_layout)?;
104104
if new_layout.size() > 0 {
105-
new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), old_layout.size());
106-
self.deallocate(ptr, old_layout);
105+
// Safety: `new_ptr` is valid for writes and `ptr` for reads of
106+
// `old_layout.size()`, because `new_layout.size() >=
107+
// old_layout.size()` (which is an invariant that must be upheld by
108+
// callers).
109+
unsafe {
110+
new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), old_layout.size());
111+
}
112+
// Safety: `ptr` is never used again is also an invariant which must
113+
// be upheld by callers.
114+
unsafe {
115+
self.deallocate(ptr, old_layout);
116+
}
107117
}
108118
Ok(new_ptr)
109119
}
@@ -114,12 +124,21 @@ unsafe impl const Allocator for ConstAllocator {
114124
old_layout: Layout,
115125
new_layout: Layout,
116126
) -> Result<NonNull<[u8]>, AllocError> {
117-
let new_ptr = self.grow(ptr, old_layout, new_layout)?;
127+
// Safety: Invariants of `grow_zeroed` and `grow` are the same, and must
128+
// be enforced by callers.
129+
let new_ptr = unsafe { self.grow(ptr, old_layout, new_layout)? };
118130
if new_layout.size() > 0 {
119131
let old_size = old_layout.size();
120132
let new_size = new_layout.size();
121133
let raw_ptr = new_ptr.as_mut_ptr();
122-
raw_ptr.add(old_size).write_bytes(0, new_size - old_size);
134+
// Safety:
135+
// - `grow` returned Ok, so the returned pointer must be valid for
136+
// `new_size` bytes
137+
// - `new_size` must be larger than `old_size`, which is an
138+
// invariant which must be upheld by callers.
139+
unsafe {
140+
raw_ptr.add(old_size).write_bytes(0, new_size - old_size);
141+
}
123142
}
124143
Ok(new_ptr)
125144
}
@@ -137,8 +156,18 @@ unsafe impl const Allocator for ConstAllocator {
137156

138157
let new_ptr = self.allocate(new_layout)?;
139158
if new_layout.size() > 0 {
140-
new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), new_layout.size());
141-
self.deallocate(ptr, old_layout);
159+
// Safety: `new_ptr` and `ptr` are valid for reads/writes of
160+
// `new_layout.size()` because of the invariants of shrink, which
161+
// include `new_layout.size()` being smaller than (or equal to)
162+
// `old_layout.size()`.
163+
unsafe {
164+
new_ptr.as_mut_ptr().copy_from_nonoverlapping(ptr.as_ptr(), new_layout.size());
165+
}
166+
// Safety: `ptr` is never used again is also an invariant which must
167+
// be upheld by callers.
168+
unsafe {
169+
self.deallocate(ptr, old_layout);
170+
}
142171
}
143172
Ok(new_ptr)
144173
}

library/alloc/tests/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
#![feature(once_cell)]
4949
#![feature(drain_keep_rest)]
5050
#![deny(fuzzy_provenance_casts)]
51+
#![deny(unsafe_op_in_unsafe_fn)]
5152

5253
use std::collections::hash_map::DefaultHasher;
5354
use std::hash::{Hash, Hasher};

library/alloc/tests/vec.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,8 @@ fn test_into_iter_drop_allocator() {
10891089
}
10901090

10911091
unsafe fn deallocate(&self, ptr: NonNull<u8>, layout: Layout) {
1092-
System.deallocate(ptr, layout)
1092+
// Safety: Invariants passed to caller.
1093+
unsafe { System.deallocate(ptr, layout) }
10931094
}
10941095
}
10951096

library/core/src/cell.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ impl<T: ?Sized> RefCell<T> {
10251025
///
10261026
/// Since this method borrows `RefCell` mutably, it is statically guaranteed
10271027
/// that no borrows to the underlying data exist. The dynamic checks inherent
1028-
/// in [`borrow_mut`] and most other methods of `RefCell` are therefor
1028+
/// in [`borrow_mut`] and most other methods of `RefCell` are therefore
10291029
/// unnecessary.
10301030
///
10311031
/// This method can only be called if `RefCell` can be mutably borrowed,

src/bootstrap/dist.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1191,7 +1191,6 @@ impl Step for Clippy {
11911191

11921192
let mut tarball = Tarball::new(builder, "clippy", &target.triple);
11931193
tarball.set_overlay(OverlayKind::Clippy);
1194-
tarball.is_preview(true);
11951194
tarball.add_file(clippy, "bin", 0o755);
11961195
tarball.add_file(cargoclippy, "bin", 0o755);
11971196
tarball.add_legal_and_readme_to("share/doc/clippy");
@@ -1289,7 +1288,6 @@ impl Step for Rustfmt {
12891288
.expect("cargo fmt expected to build - essential tool");
12901289
let mut tarball = Tarball::new(builder, "rustfmt", &target.triple);
12911290
tarball.set_overlay(OverlayKind::Rustfmt);
1292-
tarball.is_preview(true);
12931291
tarball.add_file(rustfmt, "bin", 0o755);
12941292
tarball.add_file(cargofmt, "bin", 0o755);
12951293
tarball.add_legal_and_readme_to("share/doc/rustfmt");
@@ -1550,8 +1548,6 @@ impl Step for Extended {
15501548
format!("{}-{}", name, target.triple)
15511549
} else if name == "rust-analyzer" {
15521550
"rust-analyzer-preview".to_string()
1553-
} else if name == "clippy" {
1554-
"clippy-preview".to_string()
15551551
} else if name == "rust-demangler" {
15561552
"rust-demangler-preview".to_string()
15571553
} else if name == "miri" {

src/bootstrap/download.rs

+2
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ impl Config {
326326
}
327327

328328
let filename = format!("rustfmt-{version}-{build}.tar.xz", build = host.triple);
329+
// cfg(bootstrap): will need to be changed from `rustfmt-preview` to `rustfmt` the next time you run `bump-stage0`.
330+
// See <https://github.com/rust-lang/rust/pull/103648>
329331
self.download_component(DownloadSource::Dist, filename, "rustfmt-preview", &date, "stage0");
330332

331333
self.fix_bin_or_dylib(&bin_root.join("bin").join("rustfmt"));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# `abi_efiapi`
2+
3+
The tracking issue for this feature is: [#65815]
4+
5+
[#65815]: https://github.com/rust-lang/rust/issues/65815
6+
7+
------------------------
8+
9+
The `efiapi` calling convention can be used for defining a function with
10+
an ABI compatible with the UEFI Interfaces as defined in the [UEFI
11+
Specification].
12+
13+
Example:
14+
15+
```rust
16+
#![feature(abi_efiapi)]
17+
18+
extern "efiapi" { fn f1(); }
19+
20+
extern "efiapi" fn f2() { todo!() }
21+
```
22+
23+
[UEFI Specification]: https://uefi.org/specs/UEFI/2.10/

src/librustdoc/html/static/css/rustdoc.css

+7
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,13 @@ a.test-arrow:hover {
13431343
border-bottom: 1px solid var(--border-color);
13441344
margin-bottom: 6px;
13451345
}
1346+
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
1347+
#source-sidebar div.files > a:focus, details.dir-entry summary:focus {
1348+
background-color: var(--source-sidebar-background-hover);
1349+
}
1350+
#source-sidebar div.files > a.selected {
1351+
background-color: var(--source-sidebar-background-selected);
1352+
}
13461353
#sidebar-toggle > button {
13471354
font-size: inherit;
13481355
font-weight: bold;

src/librustdoc/html/static/css/themes/ayu.css

+3-5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ Original by Dempfi (https://github.com/dempfi/ayu)
8484
--crate-search-div-hover-filter: invert(98%) sepia(12%) saturate(81%) hue-rotate(343deg)
8585
brightness(113%) contrast(76%);
8686
--crate-search-hover-border: #e0e0e0;
87+
--source-sidebar-background-selected: #14191f;
88+
--source-sidebar-background-hover: #14191f;
8789
}
8890

8991
h1, h2, h3, h4 {
@@ -208,12 +210,8 @@ pre.rust .kw-2, pre.rust .prelude-ty {}
208210
color: #fff;
209211
}
210212
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
211-
#source-sidebar div.files > a:focus, details.dir-entry summary:focus {
212-
background-color: #14191f;
213-
color: #ffb44c;
214-
}
213+
#source-sidebar div.files > a:focus, details.dir-entry summary:focus,
215214
#source-sidebar div.files > a.selected {
216-
background-color: #14191f;
217215
color: #ffb44c;
218216
}
219217

src/librustdoc/html/static/css/themes/dark.css

+2-8
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
--crate-search-div-hover-filter: invert(69%) sepia(60%) saturate(6613%) hue-rotate(184deg)
8080
brightness(100%) contrast(91%);
8181
--crate-search-hover-border: #2196f3;
82+
--source-sidebar-background-selected: #333;
83+
--source-sidebar-background-hover: #444;
8284
}
8385

8486
.content .item-info::before { color: #ccc; }
@@ -105,14 +107,6 @@ details.rustdoc-toggle > summary::before {
105107
color: #888;
106108
}
107109

108-
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
109-
#source-sidebar div.files > a:focus, details.dir-entry summary:focus {
110-
background-color: #444;
111-
}
112-
#source-sidebar div.files > a.selected {
113-
background-color: #333;
114-
}
115-
116110
.scraped-example-list .scrape-help {
117111
border-color: #aaa;
118112
color: #eee;

src/librustdoc/html/static/css/themes/light.css

+2-7
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@
7676
--crate-search-div-hover-filter: invert(44%) sepia(18%) saturate(23%) hue-rotate(317deg)
7777
brightness(96%) contrast(93%);
7878
--crate-search-hover-border: #717171;
79+
--source-sidebar-background-selected: #fff;
80+
--source-sidebar-background-hover: #e0e0e0;
7981
}
8082

8183
.content .item-info::before { color: #ccc; }
@@ -98,13 +100,6 @@ body.source .example-wrap pre.rust a {
98100
color: #888;
99101
}
100102

101-
#source-sidebar div.files > a:hover, details.dir-entry summary:hover,
102-
#source-sidebar div.files > a:focus, details.dir-entry summary:focus {
103-
background-color: #E0E0E0;
104-
}
105-
#source-sidebar div.files > a.selected {
106-
background-color: #fff;
107-
}
108103
.scraped-example-list .scrape-help {
109104
border-color: #555;
110105
color: #333;

0 commit comments

Comments
 (0)