Skip to content

Commit 47365c0

Browse files
committed
Auto merge of #97566 - compiler-errors:rollup-qfxw4j8, r=compiler-errors
Rollup of 6 pull requests Successful merges: - #89685 (refactor: VecDeques Iter fields to private) - #97172 (Optimize the diagnostic generation for `extern unsafe`) - #97395 (Miri call ABI check: ensure type size+align stay the same) - #97431 (don't do `Sized` and other return type checks on RPIT's real type) - #97555 (Source code page: line number click adds `NaN`) - #97558 (Fix typos in comment) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 7be9ec2 + b3dc31c commit 47365c0

File tree

13 files changed

+120
-61
lines changed

13 files changed

+120
-61
lines changed

compiler/rustc_const_eval/src/interpret/terminator.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
185185
// No question
186186
return true;
187187
}
188-
// Compare layout
188+
if caller_abi.layout.size != callee_abi.layout.size
189+
|| caller_abi.layout.align.abi != callee_abi.layout.align.abi
190+
{
191+
// This cannot go well...
192+
// FIXME: What about unsized types?
193+
return false;
194+
}
195+
// The rest *should* be okay, but we are extra conservative.
189196
match (caller_abi.layout.abi, callee_abi.layout.abi) {
190197
// Different valid ranges are okay (once we enforce validity,
191198
// that will take care to make it UB to leave the range, just

compiler/rustc_data_structures/src/stable_hasher.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ fn stable_hash_reduce<HCX, I, C, F>(
632632
}
633633
}
634634

635-
/// Controls what data we do or not not hash.
635+
/// Controls what data we do or do not hash.
636636
/// Whenever a `HashStable` implementation caches its
637637
/// result, it needs to include `HashingControls` as part
638-
/// of the key, to ensure that is does not produce an incorrect
638+
/// of the key, to ensure that it does not produce an incorrect
639639
/// result (for example, using a `Fingerprint` produced while
640640
/// hashing `Span`s when a `Fingerprint` without `Span`s is
641641
/// being requested)

compiler/rustc_parse/src/parser/item.rs

+15-26
Original file line numberDiff line numberDiff line change
@@ -996,35 +996,24 @@ impl<'a> Parser<'a> {
996996
fn parse_item_foreign_mod(
997997
&mut self,
998998
attrs: &mut Vec<Attribute>,
999-
unsafety: Unsafe,
999+
mut unsafety: Unsafe,
10001000
) -> PResult<'a, ItemInfo> {
1001-
let sp_start = self.prev_token.span;
10021001
let abi = self.parse_abi(); // ABI?
1003-
match self.parse_item_list(attrs, |p| p.parse_foreign_item(ForceCollect::No)) {
1004-
Ok(items) => {
1005-
let module = ast::ForeignMod { unsafety, abi, items };
1006-
Ok((Ident::empty(), ItemKind::ForeignMod(module)))
1007-
}
1008-
Err(mut err) => {
1009-
let current_qual_sp = self.prev_token.span;
1010-
let current_qual_sp = current_qual_sp.to(sp_start);
1011-
if let Ok(current_qual) = self.span_to_snippet(current_qual_sp) {
1012-
// FIXME(davidtwco): avoid depending on the error message text
1013-
if err.message[0].0.expect_str() == "expected `{`, found keyword `unsafe`" {
1014-
let invalid_qual_sp = self.token.uninterpolated_span();
1015-
let invalid_qual = self.span_to_snippet(invalid_qual_sp).unwrap();
1016-
1017-
err.span_suggestion(
1018-
current_qual_sp.to(invalid_qual_sp),
1019-
&format!("`{}` must come before `{}`", invalid_qual, current_qual),
1020-
format!("{} {}", invalid_qual, current_qual),
1021-
Applicability::MachineApplicable,
1022-
).note("keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`");
1023-
}
1024-
}
1025-
Err(err)
1026-
}
1002+
if unsafety == Unsafe::No
1003+
&& self.token.is_keyword(kw::Unsafe)
1004+
&& self.look_ahead(1, |t| t.kind == token::OpenDelim(Delimiter::Brace))
1005+
{
1006+
let mut err = self.expect(&token::OpenDelim(Delimiter::Brace)).unwrap_err();
1007+
err.emit();
1008+
unsafety = Unsafe::Yes(self.token.span);
1009+
self.eat_keyword(kw::Unsafe);
10271010
}
1011+
let module = ast::ForeignMod {
1012+
unsafety,
1013+
abi,
1014+
items: self.parse_item_list(attrs, |p| p.parse_foreign_item(ForceCollect::No))?,
1015+
};
1016+
Ok((Ident::empty(), ItemKind::ForeignMod(module)))
10281017
}
10291018

10301019
/// Parses a foreign item (one in an `extern { ... }` block).

compiler/rustc_typeck/src/check/check.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,6 @@ pub(super) fn check_fn<'a, 'tcx>(
105105
DUMMY_SP,
106106
param_env,
107107
));
108-
// HACK(oli-obk): we rewrite the declared return type, too, so that we don't end up inferring all
109-
// unconstrained RPIT to have `()` as their hidden type. This would happen because further down we
110-
// compare the ret_coercion with declared_ret_ty, and anything uninferred would be inferred to the
111-
// opaque type itself. That again would cause writeback to assume we have a recursive call site
112-
// and do the sadly stabilized fallback to `()`.
113-
let declared_ret_ty = ret_ty;
114108
fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(ret_ty)));
115109
fcx.ret_type_span = Some(decl.output.span());
116110

@@ -254,7 +248,12 @@ pub(super) fn check_fn<'a, 'tcx>(
254248
fcx.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::DynReturnFn, span });
255249
debug!("actual_return_ty replaced with {:?}", actual_return_ty);
256250
}
257-
fcx.demand_suptype(span, declared_ret_ty, actual_return_ty);
251+
252+
// HACK(oli-obk, compiler-errors): We should be comparing this against
253+
// `declared_ret_ty`, but then anything uninferred would be inferred to
254+
// the opaque type itself. That again would cause writeback to assume
255+
// we have a recursive call site and do the sadly stabilized fallback to `()`.
256+
fcx.demand_suptype(span, ret_ty, actual_return_ty);
258257

259258
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
260259
if let Some(panic_impl_did) = tcx.lang_items().panic_impl()

library/alloc/src/collections/vec_deque/iter.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,15 @@ use super::{count, wrap_index, RingSlices};
1313
/// [`iter`]: super::VecDeque::iter
1414
#[stable(feature = "rust1", since = "1.0.0")]
1515
pub struct Iter<'a, T: 'a> {
16-
pub(crate) ring: &'a [MaybeUninit<T>],
17-
pub(crate) tail: usize,
18-
pub(crate) head: usize,
16+
ring: &'a [MaybeUninit<T>],
17+
tail: usize,
18+
head: usize,
19+
}
20+
21+
impl<'a, T> Iter<'a, T> {
22+
pub(super) fn new(ring: &'a [MaybeUninit<T>], tail: usize, head: usize) -> Self {
23+
Iter { ring, tail, head }
24+
}
1925
}
2026

2127
#[stable(feature = "collection_debug", since = "1.17.0")]

library/alloc/src/collections/vec_deque/mod.rs

+8-13
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ impl<T, A: Allocator> VecDeque<T, A> {
10131013
/// ```
10141014
#[stable(feature = "rust1", since = "1.0.0")]
10151015
pub fn iter(&self) -> Iter<'_, T> {
1016-
Iter { tail: self.tail, head: self.head, ring: unsafe { self.buffer_as_slice() } }
1016+
Iter::new(unsafe { self.buffer_as_slice() }, self.tail, self.head)
10171017
}
10181018

10191019
/// Returns a front-to-back iterator that returns mutable references.
@@ -1192,12 +1192,8 @@ impl<T, A: Allocator> VecDeque<T, A> {
11921192
R: RangeBounds<usize>,
11931193
{
11941194
let (tail, head) = self.range_tail_head(range);
1195-
Iter {
1196-
tail,
1197-
head,
1198-
// The shared reference we have in &self is maintained in the '_ of Iter.
1199-
ring: unsafe { self.buffer_as_slice() },
1200-
}
1195+
// The shared reference we have in &self is maintained in the '_ of Iter.
1196+
Iter::new(unsafe { self.buffer_as_slice() }, tail, head)
12011197
}
12021198

12031199
/// Creates an iterator that covers the specified mutable range in the deque.
@@ -1313,16 +1309,15 @@ impl<T, A: Allocator> VecDeque<T, A> {
13131309
self.head = drain_tail;
13141310

13151311
let deque = NonNull::from(&mut *self);
1316-
let iter = Iter {
1317-
tail: drain_tail,
1318-
head: drain_head,
1312+
unsafe {
13191313
// Crucially, we only create shared references from `self` here and read from
13201314
// it. We do not write to `self` nor reborrow to a mutable reference.
13211315
// Hence the raw pointer we created above, for `deque`, remains valid.
1322-
ring: unsafe { self.buffer_as_slice() },
1323-
};
1316+
let ring = self.buffer_as_slice();
1317+
let iter = Iter::new(ring, drain_tail, drain_head);
13241318

1325-
unsafe { Drain::new(drain_head, head, iter, deque) }
1319+
Drain::new(drain_head, head, iter, deque)
1320+
}
13261321
}
13271322

13281323
/// Clears the deque, removing all values.

src/librustdoc/html/static/js/source-script.js

+4
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,10 @@ const handleSourceHighlight = (function() {
205205

206206
return ev => {
207207
let cur_line_id = parseInt(ev.target.id, 10);
208+
// It can happen when clicking not on a line number span.
209+
if (isNaN(cur_line_id)) {
210+
return;
211+
}
208212
ev.preventDefault();
209213

210214
if (ev.shiftKey && prev_line_id) {

src/test/rustdoc-gui/source-code-page.goml

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
33
// Check that we can click on the line number.
44
click: ".line-numbers > span:nth-child(4)" // This is the span for line 4.
5-
// Unfortunately, "#4" isn't a valid query selector, so we have to go around that limitation
6-
// by instead getting the nth span.
7-
assert-attribute: (".line-numbers > span:nth-child(4)", {"class": "line-highlighted"})
5+
// Ensure that the page URL was updated.
6+
assert-document-property: ({"URL": "lib.rs.html#4"}, ENDS_WITH)
7+
assert-attribute: ("//*[@id='4']", {"class": "line-highlighted"})
88
// We now check that the good spans are highlighted
99
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html#4-6
1010
assert-attribute-false: (".line-numbers > span:nth-child(3)", {"class": "line-highlighted"})
@@ -17,3 +17,13 @@ compare-elements-position: ("//*[@id='1']", ".rust > code > span", ("y"))
1717

1818
// Assert that the line numbers text is aligned to the right.
1919
assert-css: (".line-numbers", {"text-align": "right"})
20+
21+
// Now let's check that clicking on something else than the line number doesn't
22+
// do anything (and certainly not add a `#NaN` to the URL!).
23+
show-text: true
24+
goto: file://|DOC_PATH|/src/test_docs/lib.rs.html
25+
// We use this assert-position to know where we will click.
26+
assert-position: ("//*[@id='1']", {"x": 104, "y": 103})
27+
// We click on the left of the "1" span but still in the "line-number" `<pre>`.
28+
click: (103, 103)
29+
assert-document-property: ({"URL": "/lib.rs.html"}, ENDS_WITH)
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo() -> impl ?Sized {
2+
//~^ ERROR the size for values of type `impl ?Sized` cannot be known at compilation time
3+
()
4+
}
5+
6+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0277]: the size for values of type `impl ?Sized` cannot be known at compilation time
2+
--> $DIR/rpit-not-sized.rs:1:13
3+
|
4+
LL | fn foo() -> impl ?Sized {
5+
| ^^^^^^^^^^^ doesn't have a size known at compile-time
6+
|
7+
= help: the trait `Sized` is not implemented for `impl ?Sized`
8+
= note: the return type of a function must have a statically known size
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/parser/issues/issue-19398.stderr

+1-6
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,10 @@ error: expected `{`, found keyword `unsafe`
44
LL | trait T {
55
| - while parsing this item list starting here
66
LL | extern "Rust" unsafe fn foo();
7-
| --------------^^^^^^
8-
| | |
9-
| | expected `{`
10-
| help: `unsafe` must come before `extern "Rust"`: `unsafe extern "Rust"`
7+
| ^^^^^^ expected `{`
118
LL |
129
LL | }
1310
| - the item list ends here
14-
|
15-
= note: keyword order for functions declaration is `pub`, `default`, `const`, `async`, `unsafe`, `extern`
1611

1712
error: aborting due to previous error
1813

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
extern "C" unsafe {
2+
//~^ ERROR expected `{`, found keyword `unsafe`
3+
//~| ERROR extern block cannot be declared unsafe
4+
unsafe fn foo();
5+
//~^ ERROR functions in `extern` blocks cannot have qualifiers
6+
}
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
error: expected `{`, found keyword `unsafe`
2+
--> $DIR/unsafe-foreign-mod-2.rs:1:12
3+
|
4+
LL | extern "C" unsafe {
5+
| ^^^^^^ expected `{`
6+
7+
error: extern block cannot be declared unsafe
8+
--> $DIR/unsafe-foreign-mod-2.rs:1:12
9+
|
10+
LL | extern "C" unsafe {
11+
| ^^^^^^
12+
13+
error: functions in `extern` blocks cannot have qualifiers
14+
--> $DIR/unsafe-foreign-mod-2.rs:4:15
15+
|
16+
LL | extern "C" unsafe {
17+
| ----------------- in this `extern` block
18+
...
19+
LL | unsafe fn foo();
20+
| ^^^
21+
|
22+
help: remove the qualifiers
23+
|
24+
LL | fn foo();
25+
| ~~
26+
27+
error: aborting due to 3 previous errors
28+

0 commit comments

Comments
 (0)