Skip to content

Commit 0519628

Browse files
committed
Auto merge of #148813 - Zalathar:rollup-xsibgvo, r=Zalathar
Rollup of 16 pull requests Successful merges: - #141470 (Add new `function_casts_as_integer` lint) - #143619 (`c_variadic`: Add future-incompatibility warning for `...` arguments without a pattern outside of `extern` blocks) - #146495 (rustdoc: Erase `#![doc(document_private_items)]`) - #147771 (Rename `*exact_{div,shr,shl}` to `*{div,shr,shl}_exact`) - #147833 (rustdoc-json: move `target` to `json::conversions`) - #147952 (Add a timeout to the `remote-test-client` connection) - #147955 (compiletest: Migrate `TestProps` directive handling to a system of named handlers) - #148480 (Add `Steal::risky_hack_borrow_mut`) - #148506 (Special case detecting `'static` lifetime requirement coming from `-> Box<dyn Trait>`) - #148508 (Provide more context when mutably borrowing an imutably borrowed value) - #148530 (update the bootstrap readme) - #148608 (Add test for --test-builder success path) - #148636 (bootstrap: respect `build.python` on macOS) - #148639 (test(rustdoc): move tests into jump-to-def) - #148647 (Check unsafety for non-macro attributes in `validate_attr`) - #148667 (a few small clippy fixes) r? `@ghost` `@rustbot` modify labels: rollup
2 parents c8f22ca + 1edec6c commit 0519628

File tree

233 files changed

+2169
-958
lines changed

Some content is hidden

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

233 files changed

+2169
-958
lines changed

Cargo.lock

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,21 @@ dependencies = [
229229
"winnow 0.7.13",
230230
]
231231

232+
[[package]]
233+
name = "assert_cmd"
234+
version = "2.1.1"
235+
source = "registry+https://github.com/rust-lang/crates.io-index"
236+
checksum = "bcbb6924530aa9e0432442af08bbcafdad182db80d2e560da42a6d442535bf85"
237+
dependencies = [
238+
"anstyle",
239+
"bstr",
240+
"libc",
241+
"predicates",
242+
"predicates-core",
243+
"predicates-tree",
244+
"wait-timeout",
245+
]
246+
232247
[[package]]
233248
name = "autocfg"
234249
version = "1.5.0"
@@ -1128,6 +1143,12 @@ version = "0.1.13"
11281143
source = "registry+https://github.com/rust-lang/crates.io-index"
11291144
checksum = "56254986775e3233ffa9c4d7d3faaf6d36a2c09d30b20687e9f88bc8bafc16c8"
11301145

1146+
[[package]]
1147+
name = "difflib"
1148+
version = "0.4.0"
1149+
source = "registry+https://github.com/rust-lang/crates.io-index"
1150+
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
1151+
11311152
[[package]]
11321153
name = "digest"
11331154
version = "0.10.7"
@@ -2949,6 +2970,33 @@ version = "0.1.1"
29492970
source = "registry+https://github.com/rust-lang/crates.io-index"
29502971
checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
29512972

2973+
[[package]]
2974+
name = "predicates"
2975+
version = "3.1.3"
2976+
source = "registry+https://github.com/rust-lang/crates.io-index"
2977+
checksum = "a5d19ee57562043d37e82899fade9a22ebab7be9cef5026b07fda9cdd4293573"
2978+
dependencies = [
2979+
"anstyle",
2980+
"difflib",
2981+
"predicates-core",
2982+
]
2983+
2984+
[[package]]
2985+
name = "predicates-core"
2986+
version = "1.0.9"
2987+
source = "registry+https://github.com/rust-lang/crates.io-index"
2988+
checksum = "727e462b119fe9c93fd0eb1429a5f7647394014cf3c04ab2c0350eeb09095ffa"
2989+
2990+
[[package]]
2991+
name = "predicates-tree"
2992+
version = "1.0.12"
2993+
source = "registry+https://github.com/rust-lang/crates.io-index"
2994+
checksum = "72dd2d6d381dfb73a193c7fca536518d7caee39fc8503f74e7dc0be0531b425c"
2995+
dependencies = [
2996+
"predicates-core",
2997+
"termtree",
2998+
]
2999+
29523000
[[package]]
29533001
name = "prettydiff"
29543002
version = "0.7.0"
@@ -3229,6 +3277,9 @@ checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
32293277
[[package]]
32303278
name = "remote-test-client"
32313279
version = "0.1.0"
3280+
dependencies = [
3281+
"assert_cmd",
3282+
]
32323283

32333284
[[package]]
32343285
name = "remote-test-server"
@@ -5425,6 +5476,12 @@ dependencies = [
54255476
"windows-sys 0.60.2",
54265477
]
54275478

5479+
[[package]]
5480+
name = "termtree"
5481+
version = "0.5.1"
5482+
source = "registry+https://github.com/rust-lang/crates.io-index"
5483+
checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
5484+
54285485
[[package]]
54295486
name = "test-float-parse"
54305487
version = "0.1.0"
@@ -6043,6 +6100,15 @@ version = "0.9.5"
60436100
source = "registry+https://github.com/rust-lang/crates.io-index"
60446101
checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a"
60456102

6103+
[[package]]
6104+
name = "wait-timeout"
6105+
version = "0.2.1"
6106+
source = "registry+https://github.com/rust-lang/crates.io-index"
6107+
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
6108+
dependencies = [
6109+
"libc",
6110+
]
6111+
60466112
[[package]]
60476113
name = "walkdir"
60486114
version = "2.5.0"

compiler/rustc_ast_lowering/src/index.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,9 @@ impl<'a, 'hir> NodeCollector<'a, 'hir> {
125125
}
126126

127127
impl<'a, 'hir> Visitor<'hir> for NodeCollector<'a, 'hir> {
128-
/// Because we want to track parent items and so forth, enable
129-
/// deep walking so that we walk nested items in the context of
130-
/// their outer items.
128+
// Because we want to track parent items and so forth, enable
129+
// deep walking so that we walk nested items in the context of
130+
// their outer items.
131131

132132
fn visit_nested_item(&mut self, item: ItemId) {
133133
debug!("visit_nested_item: {:?}", item);

compiler/rustc_attr_parsing/src/validate_attr.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ pub fn check_attribute_safety(
209209

210210
// - Normal builtin attribute
211211
// - Writing `#[unsafe(..)]` is not permitted on normal builtin attributes
212-
(Some(AttributeSafety::Normal), Safety::Unsafe(unsafe_span)) => {
212+
(None | Some(AttributeSafety::Normal), Safety::Unsafe(unsafe_span)) => {
213213
psess.dcx().emit_err(errors::InvalidAttrUnsafe {
214214
span: unsafe_span,
215215
name: attr_item.path.clone(),
@@ -218,15 +218,10 @@ pub fn check_attribute_safety(
218218

219219
// - Normal builtin attribute
220220
// - No explicit `#[unsafe(..)]` written.
221-
(Some(AttributeSafety::Normal), Safety::Default) => {
221+
(None | Some(AttributeSafety::Normal), Safety::Default) => {
222222
// OK
223223
}
224224

225-
// - Non-builtin attribute
226-
(None, Safety::Unsafe(_) | Safety::Default) => {
227-
// OK (not checked here)
228-
}
229-
230225
(
231226
Some(AttributeSafety::Unsafe { .. } | AttributeSafety::Normal) | None,
232227
Safety::Safe(..),

compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
213213
AccessKind::Mutate => {
214214
err = self.cannot_assign(span, &(item_msg + &reason));
215215
act = "assign";
216-
acted_on = "written";
216+
acted_on = "written to";
217217
span
218218
}
219219
AccessKind::MutableBorrow => {
@@ -518,8 +518,8 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
518518
err.span_label(
519519
span,
520520
format!(
521-
"`{name}` is a `{pointer_sigil}` {pointer_desc}, \
522-
so the data it refers to cannot be {acted_on}",
521+
"`{name}` is a `{pointer_sigil}` {pointer_desc}, so it cannot be \
522+
{acted_on}",
523523
),
524524
);
525525

@@ -542,7 +542,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
542542
self.expected_fn_found_fn_mut_call(&mut err, span, act);
543543
}
544544

545-
PlaceRef { local: _, projection: [.., ProjectionElem::Deref] } => {
545+
PlaceRef { local, projection: [.., ProjectionElem::Deref] } => {
546546
err.span_label(span, format!("cannot {act}"));
547547

548548
match opt_source {
@@ -559,11 +559,36 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
559559
));
560560
self.suggest_map_index_mut_alternatives(ty, &mut err, span);
561561
}
562-
_ => (),
562+
_ => {
563+
let local = &self.body.local_decls[local];
564+
match local.local_info() {
565+
LocalInfo::StaticRef { def_id, .. } => {
566+
let span = self.infcx.tcx.def_span(def_id);
567+
err.span_label(span, format!("this `static` cannot be {acted_on}"));
568+
}
569+
LocalInfo::ConstRef { def_id } => {
570+
let span = self.infcx.tcx.def_span(def_id);
571+
err.span_label(span, format!("this `const` cannot be {acted_on}"));
572+
}
573+
LocalInfo::BlockTailTemp(_) | LocalInfo::Boring
574+
if !local.source_info.span.overlaps(span) =>
575+
{
576+
err.span_label(
577+
local.source_info.span,
578+
format!("this cannot be {acted_on}"),
579+
);
580+
}
581+
_ => {}
582+
}
583+
}
563584
}
564585
}
565586

566-
_ => {
587+
PlaceRef { local, .. } => {
588+
let local = &self.body.local_decls[local];
589+
if !local.source_info.span.overlaps(span) {
590+
err.span_label(local.source_info.span, format!("this cannot be {acted_on}"));
591+
}
567592
err.span_label(span, format!("cannot {act}"));
568593
}
569594
}

compiler/rustc_data_structures/src/steal.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::stable_hasher::{HashStable, StableHasher};
2-
use crate::sync::{MappedReadGuard, ReadGuard, RwLock};
2+
use crate::sync::{MappedReadGuard, MappedWriteGuard, ReadGuard, RwLock, WriteGuard};
33

44
/// The `Steal` struct is intended to used as the value for a query.
55
/// Specifically, we sometimes have queries (*cough* MIR *cough*)
@@ -40,9 +40,17 @@ impl<T> Steal<T> {
4040
ReadGuard::map(borrow, |opt| opt.as_ref().unwrap())
4141
}
4242

43+
/// An escape hatch for rustc drivers to mutate `Steal` caches.
44+
///
45+
/// Use at your own risk. This can badly break incremental compilation
46+
/// and anything else that relies on the immutability of query caches.
4347
#[track_caller]
44-
pub fn get_mut(&mut self) -> &mut T {
45-
self.value.get_mut().as_mut().expect("attempt to read from stolen value")
48+
pub fn risky_hack_borrow_mut(&self) -> MappedWriteGuard<'_, T> {
49+
let borrow = self.value.borrow_mut();
50+
if borrow.is_none() {
51+
panic!("attempted to read from stolen value: {}", std::any::type_name::<T>());
52+
}
53+
WriteGuard::map(borrow, |opt| opt.as_mut().unwrap())
4654
}
4755

4856
#[track_caller]

compiler/rustc_driver_impl/src/signal_handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,8 @@ pub(super) fn install() {
152152
libc::sigaltstack(&alt_stack, ptr::null_mut());
153153

154154
let mut sa: libc::sigaction = mem::zeroed();
155-
sa.sa_sigaction = print_stack_trace as libc::sighandler_t;
155+
sa.sa_sigaction =
156+
print_stack_trace as unsafe extern "C" fn(libc::c_int) as libc::sighandler_t;
156157
sa.sa_flags = libc::SA_NODEFER | libc::SA_RESETHAND | libc::SA_ONSTACK;
157158
libc::sigemptyset(&mut sa.sa_mask);
158159
for (signum, _signame) in KILL_SIGNALS {

compiler/rustc_errors/src/emitter.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2322,11 +2322,6 @@ impl HumanEmitter {
23222322
show_code_change
23232323
{
23242324
for part in parts {
2325-
let snippet = if let Ok(snippet) = sm.span_to_snippet(part.span) {
2326-
snippet
2327-
} else {
2328-
String::new()
2329-
};
23302325
let span_start_pos = sm.lookup_char_pos(part.span.lo()).col_display;
23312326
let span_end_pos = sm.lookup_char_pos(part.span.hi()).col_display;
23322327

@@ -2402,7 +2397,7 @@ impl HumanEmitter {
24022397
// LL - REMOVED <- row_num - 2 - (newlines - first_i - 1)
24032398
// LL + NEWER
24042399
// | <- row_num
2405-
2400+
let snippet = sm.span_to_snippet(part.span).unwrap_or_default();
24062401
let newlines = snippet.lines().count();
24072402
if newlines > 0 && row_num > newlines {
24082403
// Account for removals where the part being removed spans multiple

compiler/rustc_expand/src/expand.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -886,9 +886,6 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
886886
}
887887
}
888888
} else if let SyntaxExtensionKind::NonMacroAttr = ext {
889-
if let ast::Safety::Unsafe(span) = attr.get_normal_item().unsafety {
890-
self.cx.dcx().span_err(span, "unnecessary `unsafe` on safe attribute");
891-
}
892889
// `-Zmacro-stats` ignores these because they don't do any real expansion.
893890
self.cx.expanded_inert_attrs.mark(&attr);
894891
item.visit_attrs(|attrs| attrs.insert(pos, attr));

compiler/rustc_hir_analysis/src/variance/terms.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl<'a> fmt::Debug for VarianceTerm<'a> {
4444
}
4545
}
4646

47-
/// The first pass over the crate simply builds up the set of inferreds.
47+
// The first pass over the crate simply builds up the set of inferreds.
4848

4949
pub(crate) struct TermsContext<'a, 'tcx> {
5050
pub tcx: TyCtxt<'tcx>,

compiler/rustc_lint/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,9 @@ lint_forgetting_copy_types = calls to `std::mem::forget` with a value that imple
265265
lint_forgetting_references = calls to `std::mem::forget` with a reference instead of an owned value does nothing
266266
.label = argument has type `{$arg_ty}`
267267
268+
lint_function_casts_as_integer = direct cast of function item into an integer
269+
.cast_as_fn = first cast to a pointer `as *const ()`
270+
268271
lint_hidden_glob_reexport = private item shadows public glob re-export
269272
.note_glob_reexport = the name `{$name}` in the {$namespace} namespace is supposed to be publicly re-exported here
270273
.note_private_item = but the private item here shadows it

0 commit comments

Comments
 (0)