Skip to content

Commit e9b0d99

Browse files
committed
Auto merge of #90463 - matthiaskrgr:rollup-eljk9vo, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #89826 (Feature gate + make must_not_suspend allow-by-default) - #89929 (Handling submodule update failures more gracefully from x.py) - #90333 (rustdoc: remove flicker during page load) - #90349 (Fix rare ICE during typeck in rustdoc scrape_examples) - #90398 (Document `doc(keyword)` unstable attribute) - #90441 (Test that promotion follows references when looking for drop) - #90450 (Remove `rustc_hir::hir_id::HirIdVec`) - #90452 (Remove unnecessary `Option` from `promote_candidate` return type) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents db14a17 + 6ce0ef5 commit e9b0d99

File tree

31 files changed

+294
-123
lines changed

31 files changed

+294
-123
lines changed

compiler/rustc_const_eval/src/transform/promote_consts.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
835835
new_temp
836836
}
837837

838-
fn promote_candidate(
839-
mut self,
840-
candidate: Candidate,
841-
next_promoted_id: usize,
842-
) -> Option<Body<'tcx>> {
838+
fn promote_candidate(mut self, candidate: Candidate, next_promoted_id: usize) -> Body<'tcx> {
843839
let def = self.source.source.with_opt_param();
844840
let mut rvalue = {
845841
let promoted = &mut self.promoted;
@@ -938,7 +934,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
938934

939935
let span = self.promoted.span;
940936
self.assign(RETURN_PLACE, rvalue, span);
941-
Some(self.promoted)
937+
self.promoted
942938
}
943939
}
944940

@@ -1011,11 +1007,9 @@ pub fn promote_candidates<'tcx>(
10111007
keep_original: false,
10121008
};
10131009

1014-
//FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice
1015-
if let Some(mut promoted) = promoter.promote_candidate(candidate, promotions.len()) {
1016-
promoted.source.promoted = Some(promotions.next_index());
1017-
promotions.push(promoted);
1018-
}
1010+
let mut promoted = promoter.promote_candidate(candidate, promotions.len());
1011+
promoted.source.promoted = Some(promotions.next_index());
1012+
promotions.push(promoted);
10191013
}
10201014

10211015
// Insert each of `extra_statements` before its indicated location, which

compiler/rustc_hir/src/hir_id.rs

-68
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::def_id::{LocalDefId, CRATE_DEF_INDEX};
2-
use rustc_index::vec::IndexVec;
32
use std::fmt;
43

54
/// Uniquely identifies a node in the HIR of the current crate. It is
@@ -66,70 +65,3 @@ pub const CRATE_HIR_ID: HirId = HirId {
6665
owner: LocalDefId { local_def_index: CRATE_DEF_INDEX },
6766
local_id: ItemLocalId::from_u32(0),
6867
};
69-
70-
/// N.B. This collection is currently unused, but will be used by #72015 and future PRs.
71-
#[derive(Clone, Default, Debug, Encodable, Decodable)]
72-
pub struct HirIdVec<T> {
73-
map: IndexVec<LocalDefId, IndexVec<ItemLocalId, T>>,
74-
}
75-
76-
impl<T> HirIdVec<T> {
77-
pub fn push_owner(&mut self, id: LocalDefId) {
78-
self.map.ensure_contains_elem(id, IndexVec::new);
79-
}
80-
81-
pub fn push(&mut self, id: HirId, value: T) {
82-
if id.local_id == ItemLocalId::from_u32(0) {
83-
self.push_owner(id.owner);
84-
}
85-
let submap = &mut self.map[id.owner];
86-
let _ret_id = submap.push(value);
87-
debug_assert_eq!(_ret_id, id.local_id);
88-
}
89-
90-
pub fn push_sparse(&mut self, id: HirId, value: T)
91-
where
92-
T: Default,
93-
{
94-
self.map.ensure_contains_elem(id.owner, IndexVec::new);
95-
let submap = &mut self.map[id.owner];
96-
let i = id.local_id.index();
97-
let len = submap.len();
98-
if i >= len {
99-
submap.extend(std::iter::repeat_with(T::default).take(i - len + 1));
100-
}
101-
submap[id.local_id] = value;
102-
}
103-
104-
pub fn get(&self, id: HirId) -> Option<&T> {
105-
self.map.get(id.owner)?.get(id.local_id)
106-
}
107-
108-
pub fn get_owner(&self, id: LocalDefId) -> &IndexVec<ItemLocalId, T> {
109-
&self.map[id]
110-
}
111-
112-
pub fn iter(&self) -> impl Iterator<Item = &T> {
113-
self.map.iter().flat_map(|la| la.iter())
114-
}
115-
116-
pub fn iter_enumerated(&self) -> impl Iterator<Item = (HirId, &T)> {
117-
self.map.iter_enumerated().flat_map(|(owner, la)| {
118-
la.iter_enumerated().map(move |(local_id, attr)| (HirId { owner, local_id }, attr))
119-
})
120-
}
121-
}
122-
123-
impl<T> std::ops::Index<HirId> for HirIdVec<T> {
124-
type Output = T;
125-
126-
fn index(&self, id: HirId) -> &T {
127-
&self.map[id.owner][id.local_id]
128-
}
129-
}
130-
131-
impl<T> std::ops::IndexMut<HirId> for HirIdVec<T> {
132-
fn index_mut(&mut self, id: HirId) -> &mut T {
133-
&mut self.map[id.owner][id.local_id]
134-
}
135-
}

compiler/rustc_lint/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ fn register_builtins(store: &mut LintStore, no_interleave_lints: bool) {
303303
UNUSED_LABELS,
304304
UNUSED_PARENS,
305305
UNUSED_BRACES,
306-
MUST_NOT_SUSPEND,
307306
REDUNDANT_SEMICOLONS
308307
);
309308

compiler/rustc_lint_defs/src/builtin.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ declare_lint! {
323323
///
324324
/// ```rust
325325
/// #![feature(must_not_suspend)]
326+
/// #![warn(must_not_suspend)]
326327
///
327328
/// #[must_not_suspend]
328329
/// struct SyncThing {}
@@ -349,8 +350,9 @@ declare_lint! {
349350
/// `MutexGuard`'s)
350351
///
351352
pub MUST_NOT_SUSPEND,
352-
Warn,
353+
Allow,
353354
"use of a `#[must_not_suspend]` value across a yield point",
355+
@feature_gate = rustc_span::symbol::sym::must_not_suspend;
354356
}
355357

356358
declare_lint! {

src/bootstrap/bootstrap.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,15 @@ def update_submodule(self, module, checked_out, recorded_submodules):
10261026
if self.git_version >= distutils.version.LooseVersion("2.11.0"):
10271027
update_args.append("--progress")
10281028
update_args.append(module)
1029-
run(update_args, cwd=self.rust_root, verbose=self.verbose, exception=True)
1029+
try:
1030+
run(update_args, cwd=self.rust_root, verbose=self.verbose, exception=True)
1031+
except RuntimeError:
1032+
print("Failed updating submodule. This is probably due to uncommitted local changes.")
1033+
print('Either stash the changes by running "git stash" within the submodule\'s')
1034+
print('directory, reset them by running "git reset --hard", or commit them.')
1035+
print("To reset all submodules' changes run", end=" ")
1036+
print('"git submodule foreach --recursive git reset --hard".')
1037+
raise SystemExit(1)
10301038

10311039
run(["git", "reset", "-q", "--hard"],
10321040
cwd=module_path, verbose=self.verbose)

src/doc/rustdoc/src/unstable-features.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,27 @@ Book][unstable-masked] and [its tracking issue][issue-masked].
134134

135135
## Document primitives
136136

137+
This is for Rust compiler internal use only.
138+
137139
Since primitive types are defined in the compiler, there's no place to attach documentation
138-
attributes. The `#[doc(primitive)]` attribute is used by the standard library to provide a way to generate
139-
documentation for primitive types, and requires `#![feature(doc_primitive)]` to enable.
140+
attributes. The `#[doc(primitive)]` attribute is used by the standard library to provide a way
141+
to generate documentation for primitive types, and requires `#![feature(doc_primitive)]` to enable.
142+
143+
## Document keywords
144+
145+
This is for Rust compiler internal use only.
146+
147+
Rust keywords are documented in the standard library (look for `match` for example).
148+
149+
To do so, the `#[doc(keyword = "...")]` attribute is used. Example:
150+
151+
```rust
152+
#![feature(doc_keyword)]
153+
154+
/// Some documentation about the keyword.
155+
#[doc(keyword = "keyword")]
156+
mod empty_mod {}
157+
```
140158

141159
## Unstable command-line arguments
142160

src/librustdoc/html/static/css/noscript.css

+9
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,12 @@ rules.
1313
/* It requires JS to work so no need to display it in this case. */
1414
display: none;
1515
}
16+
17+
.sub {
18+
/* The search bar and related controls don't work without JS */
19+
display: none;
20+
}
21+
22+
#theme-picker {
23+
display: none;
24+
}

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

-4
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,6 @@ details.undocumented > summary::before {
255255
box-shadow: 0 0 0 1px #148099,0 0 0 2px transparent;
256256
}
257257

258-
.search-input:disabled {
259-
background-color: #3e3e3e;
260-
}
261-
262258
.module-item .stab,
263259
.import-item .stab {
264260
color: #000;

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

-4
Original file line numberDiff line numberDiff line change
@@ -219,10 +219,6 @@ details.undocumented > summary::before {
219219
border-color: #008dfd;
220220
}
221221

222-
.search-input:disabled {
223-
background-color: #c5c4c4;
224-
}
225-
226222
#crate-search + .search-input:focus {
227223
box-shadow: 0 0 8px 4px #078dd8;
228224
}

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

-4
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,6 @@ details.undocumented > summary::before {
209209
border-color: #66afe9;
210210
}
211211

212-
.search-input:disabled {
213-
background-color: #e6e6e6;
214-
}
215-
216212
#crate-search + .search-input:focus {
217213
box-shadow: 0 0 8px #078dd8;
218214
}

src/librustdoc/html/static/js/main.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,9 @@ function hideThemeButtonState() {
263263
search_input.placeholder = searchState.input.origPlaceholder;
264264
});
265265

266-
search_input.removeAttribute('disabled');
266+
if (search_input.value != '') {
267+
loadSearch();
268+
}
267269

268270
// `crates{version}.js` should always be loaded before this script, so we can use it
269271
// safely.

src/librustdoc/html/templates/page.html

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@
8585
<input {# -#}
8686
class="search-input" {# -#}
8787
name="search" {# -#}
88-
disabled {# -#}
8988
autocomplete="off" {# -#}
9089
spellcheck="false" {# -#}
9190
placeholder="Click or press ‘S’ to search, ‘?’ for more options…" {# -#}

src/librustdoc/scrape_examples.rs

+18-2
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,28 @@ where
132132
fn visit_expr(&mut self, ex: &'tcx hir::Expr<'tcx>) {
133133
intravisit::walk_expr(self, ex);
134134

135-
// Get type of function if expression is a function call
136135
let tcx = self.tcx;
136+
137+
// If we visit an item that contains an expression outside a function body,
138+
// then we need to exit before calling typeck (which will panic). See
139+
// test/run-make/rustdoc-scrape-examples-invalid-expr for an example.
140+
let hir = tcx.hir();
141+
let owner = hir.local_def_id_to_hir_id(ex.hir_id.owner);
142+
if hir.maybe_body_owned_by(owner).is_none() {
143+
return;
144+
}
145+
146+
// Get type of function if expression is a function call
137147
let (ty, span) = match ex.kind {
138148
hir::ExprKind::Call(f, _) => {
139149
let types = tcx.typeck(ex.hir_id.owner);
140-
(types.node_type(f.hir_id), ex.span)
150+
151+
match types.node_type_opt(f.hir_id) {
152+
Some(ty) => (ty, ex.span),
153+
None => {
154+
return;
155+
}
156+
}
141157
}
142158
hir::ExprKind::MethodCall(_, _, _, span) => {
143159
let types = tcx.typeck(ex.hir_id.owner);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
deps := ex
2+
3+
-include ../rustdoc-scrape-examples-multiple/scrape.mk
4+
5+
all: scrape
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub struct Foo([usize; foobar::f()]);
2+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub const fn f() -> usize { 5 }
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// @has foobar/fn.ok.html '//*[@class="docblock scraped-example-list"]//*[@class="prev"]' ''
22
// @has foobar/fn.ok.html '//*[@class="more-scraped-examples"]' ''
3+
// @has src/ex/ex.rs.html
4+
// @has foobar/fn.ok.html '//a[@href="../src/ex/ex.rs.html#2"]' ''
35

46
pub fn ok() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// When JavaScript is disabled, we hide the search bar, because it
2+
// can't be used without JS.
3+
javascript: false
4+
5+
goto: file://|DOC_PATH|/test_docs/struct.Foo.html
6+
assert-css: (".sub", {"display": "none"})

src/test/ui/async-await/issue-64130-non-send-future-diags.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition:2018
2+
#![feature(must_not_suspend)]
3+
#![allow(must_not_suspend)]
24

35
// This tests the basic example case for the async-await-specific error.
46

src/test/ui/async-await/issue-64130-non-send-future-diags.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error: future cannot be sent between threads safely
2-
--> $DIR/issue-64130-non-send-future-diags.rs:21:13
2+
--> $DIR/issue-64130-non-send-future-diags.rs:23:13
33
|
44
LL | is_send(foo());
55
| ^^^^^ future returned by `foo` is not `Send`
66
|
77
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, u32>`
88
note: future is not `Send` as this value is used across an await
9-
--> $DIR/issue-64130-non-send-future-diags.rs:15:5
9+
--> $DIR/issue-64130-non-send-future-diags.rs:17:5
1010
|
1111
LL | let g = x.lock().unwrap();
1212
| - has type `MutexGuard<'_, u32>` which is not `Send`
@@ -15,7 +15,7 @@ LL | baz().await;
1515
LL | }
1616
| - `g` is later dropped here
1717
note: required by a bound in `is_send`
18-
--> $DIR/issue-64130-non-send-future-diags.rs:7:15
18+
--> $DIR/issue-64130-non-send-future-diags.rs:9:15
1919
|
2020
LL | fn is_send<T: Send>(t: T) { }
2121
| ^^^^ required by this bound in `is_send`

src/test/ui/async-await/issue-71137.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
// edition:2018
2+
#![feature(must_not_suspend)]
3+
#![allow(must_not_suspend)]
24

35
use std::future::Future;
46
use std::sync::Mutex;

src/test/ui/async-await/issue-71137.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
error: future cannot be sent between threads safely
2-
--> $DIR/issue-71137.rs:20:14
2+
--> $DIR/issue-71137.rs:22:14
33
|
44
LL | fake_spawn(wrong_mutex());
55
| ^^^^^^^^^^^^^ future returned by `wrong_mutex` is not `Send`
66
|
77
= help: within `impl Future`, the trait `Send` is not implemented for `MutexGuard<'_, i32>`
88
note: future is not `Send` as this value is used across an await
9-
--> $DIR/issue-71137.rs:12:5
9+
--> $DIR/issue-71137.rs:14:5
1010
|
1111
LL | let mut guard = m.lock().unwrap();
1212
| --------- has type `MutexGuard<'_, i32>` which is not `Send`
@@ -16,7 +16,7 @@ LL | *guard += 1;
1616
LL | }
1717
| - `mut guard` is later dropped here
1818
note: required by a bound in `fake_spawn`
19-
--> $DIR/issue-71137.rs:6:27
19+
--> $DIR/issue-71137.rs:8:27
2020
|
2121
LL | fn fake_spawn<F: Future + Send + 'static>(f: F) { }
2222
| ^^^^ required by this bound in `fake_spawn`

src/test/ui/consts/promote-not.rs

+15
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ const TEST_INTERIOR_MUT: () = {
3939
let _val: &'static _ = &(Cell::new(1), 2).1; //~ ERROR temporary value dropped while borrowed
4040
};
4141

42+
const TEST_DROP: String = String::new();
43+
4244
fn main() {
4345
// We must not promote things with interior mutability. Not even if we "project it away".
4446
let _val: &'static _ = &(Cell::new(1), 2).0; //~ ERROR temporary value dropped while borrowed
@@ -50,4 +52,17 @@ fn main() {
5052
let _val: &'static _ = &(1%0); //~ ERROR temporary value dropped while borrowed
5153
let _val: &'static _ = &(1%(1-1)); //~ ERROR temporary value dropped while borrowed
5254
let _val: &'static _ = &([1,2,3][4]+1); //~ ERROR temporary value dropped while borrowed
55+
56+
// No promotion of temporaries that need to be dropped.
57+
let _val: &'static _ = &TEST_DROP;
58+
//~^ ERROR temporary value dropped while borrowed
59+
let _val: &'static _ = &&TEST_DROP;
60+
//~^ ERROR temporary value dropped while borrowed
61+
//~| ERROR temporary value dropped while borrowed
62+
let _val: &'static _ = &(&TEST_DROP,);
63+
//~^ ERROR temporary value dropped while borrowed
64+
//~| ERROR temporary value dropped while borrowed
65+
let _val: &'static _ = &[&TEST_DROP; 1];
66+
//~^ ERROR temporary value dropped while borrowed
67+
//~| ERROR temporary value dropped while borrowed
5368
}

0 commit comments

Comments
 (0)