Skip to content

Commit 349bda2

Browse files
committedJun 16, 2022
Auto merge of #98181 - JohnTitor:rollup-65ztwnz, r=JohnTitor
Rollup of 5 pull requests Successful merges: - #97377 (Do not suggest adding semicolon/changing delimiters for macros in item position that originates in macros) - #97675 (Make `std::mem::needs_drop` accept `?Sized`) - #98118 (Test NLL fix of bad lifetime inference for reference captured in closure.) - #98166 (Add rustdoc-json regression test for #98009) - #98169 (Keyword docs: Link to wikipedia article for dynamic dispatch) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents cacc75c + 6ac9318 commit 349bda2

File tree

13 files changed

+194
-26
lines changed

13 files changed

+194
-26
lines changed
 

‎compiler/rustc_codegen_cranelift/example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub mod intrinsics {
567567
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
568568
pub fn transmute<T, U>(e: T) -> U;
569569
pub fn ctlz_nonzero<T>(x: T) -> T;
570-
pub fn needs_drop<T>() -> bool;
570+
pub fn needs_drop<T: ?::Sized>() -> bool;
571571
pub fn bitreverse<T>(x: T) -> T;
572572
pub fn bswap<T>(x: T) -> T;
573573
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);

‎compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

+7
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ struct NoisyDrop {
5555
inner: NoisyDropInner,
5656
}
5757

58+
struct NoisyDropUnsized {
59+
inner: NoisyDropInner,
60+
text: str,
61+
}
62+
5863
struct NoisyDropInner;
5964

6065
impl Drop for NoisyDrop {
@@ -170,7 +175,9 @@ fn main() {
170175
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
171176

172177
assert!(!intrinsics::needs_drop::<u8>());
178+
assert!(!intrinsics::needs_drop::<[u8]>());
173179
assert!(intrinsics::needs_drop::<NoisyDrop>());
180+
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
174181

175182
Unique {
176183
pointer: NonNull(1 as *mut &str),

‎compiler/rustc_codegen_gcc/example/mini_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ pub mod intrinsics {
514514
pub fn copy<T>(src: *const T, dst: *mut T, count: usize);
515515
pub fn transmute<T, U>(e: T) -> U;
516516
pub fn ctlz_nonzero<T>(x: T) -> T;
517-
pub fn needs_drop<T>() -> bool;
517+
pub fn needs_drop<T: ?::Sized>() -> bool;
518518
pub fn bitreverse<T>(x: T) -> T;
519519
pub fn bswap<T>(x: T) -> T;
520520
pub fn write_bytes<T>(dst: *mut T, val: u8, count: usize);

‎compiler/rustc_codegen_gcc/example/mini_core_hello_world.rs

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ struct NoisyDrop {
4747
inner: NoisyDropInner,
4848
}
4949

50+
struct NoisyDropUnsized {
51+
inner: NoisyDropInner,
52+
text: str,
53+
}
54+
5055
struct NoisyDropInner;
5156

5257
impl Drop for NoisyDrop {
@@ -184,7 +189,9 @@ fn main() {
184189
assert_eq!(intrinsics::min_align_of_val(&a) as u8, intrinsics::min_align_of::<&str>() as u8);
185190

186191
assert!(!intrinsics::needs_drop::<u8>());
192+
assert!(!intrinsics::needs_drop::<[u8]>());
187193
assert!(intrinsics::needs_drop::<NoisyDrop>());
194+
assert!(intrinsics::needs_drop::<NoisyDropUnsized>());
188195

189196
Unique {
190197
pointer: 0 as *const &str,

‎compiler/rustc_parse/src/parser/item.rs

+25-21
Original file line numberDiff line numberDiff line change
@@ -1775,30 +1775,34 @@ impl<'a> Parser<'a> {
17751775
span,
17761776
"macros that expand to items must be delimited with braces or followed by a semicolon",
17771777
);
1778-
if self.unclosed_delims.is_empty() {
1779-
let DelimSpan { open, close } = match args {
1780-
MacArgs::Empty | MacArgs::Eq(..) => unreachable!(),
1781-
MacArgs::Delimited(dspan, ..) => *dspan,
1782-
};
1783-
err.multipart_suggestion(
1784-
"change the delimiters to curly braces",
1785-
vec![(open, "{".to_string()), (close, '}'.to_string())],
1786-
Applicability::MaybeIncorrect,
1787-
);
1788-
} else {
1778+
// FIXME: This will make us not emit the help even for declarative
1779+
// macros within the same crate (that we can fix), which is sad.
1780+
if !span.from_expansion() {
1781+
if self.unclosed_delims.is_empty() {
1782+
let DelimSpan { open, close } = match args {
1783+
MacArgs::Empty | MacArgs::Eq(..) => unreachable!(),
1784+
MacArgs::Delimited(dspan, ..) => *dspan,
1785+
};
1786+
err.multipart_suggestion(
1787+
"change the delimiters to curly braces",
1788+
vec![(open, "{".to_string()), (close, '}'.to_string())],
1789+
Applicability::MaybeIncorrect,
1790+
);
1791+
} else {
1792+
err.span_suggestion(
1793+
span,
1794+
"change the delimiters to curly braces",
1795+
" { /* items */ }",
1796+
Applicability::HasPlaceholders,
1797+
);
1798+
}
17891799
err.span_suggestion(
1790-
span,
1791-
"change the delimiters to curly braces",
1792-
" { /* items */ }",
1793-
Applicability::HasPlaceholders,
1800+
span.shrink_to_hi(),
1801+
"add a semicolon",
1802+
';',
1803+
Applicability::MaybeIncorrect,
17941804
);
17951805
}
1796-
err.span_suggestion(
1797-
span.shrink_to_hi(),
1798-
"add a semicolon",
1799-
';',
1800-
Applicability::MaybeIncorrect,
1801-
);
18021806
err.emit();
18031807
}
18041808

‎library/core/src/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1162,7 +1162,7 @@ extern "rust-intrinsic" {
11621162
///
11631163
/// The stabilized version of this intrinsic is [`mem::needs_drop`](crate::mem::needs_drop).
11641164
#[rustc_const_stable(feature = "const_needs_drop", since = "1.40.0")]
1165-
pub fn needs_drop<T>() -> bool;
1165+
pub fn needs_drop<T: ?Sized>() -> bool;
11661166

11671167
/// Calculates the offset from a pointer.
11681168
///

‎library/core/src/mem/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,7 @@ pub const unsafe fn align_of_val_raw<T: ?Sized>(val: *const T) -> usize {
592592
#[stable(feature = "needs_drop", since = "1.21.0")]
593593
#[rustc_const_stable(feature = "const_mem_needs_drop", since = "1.36.0")]
594594
#[rustc_diagnostic_item = "needs_drop"]
595-
pub const fn needs_drop<T>() -> bool {
595+
pub const fn needs_drop<T: ?Sized>() -> bool {
596596
intrinsics::needs_drop::<T>()
597597
}
598598

‎library/std/src/keyword_docs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -2257,7 +2257,7 @@ mod await_keyword {}
22572257
/// `dyn` is a prefix of a [trait object]'s type.
22582258
///
22592259
/// The `dyn` keyword is used to highlight that calls to methods on the associated `Trait`
2260-
/// are dynamically dispatched. To use the trait this way, it must be 'object safe'.
2260+
/// are [dynamically dispatched]. To use the trait this way, it must be 'object safe'.
22612261
///
22622262
/// Unlike generic parameters or `impl Trait`, the compiler does not know the concrete type that
22632263
/// is being passed. That is, the type has been [erased].
@@ -2281,6 +2281,7 @@ mod await_keyword {}
22812281
/// the method won't be duplicated for each concrete type.
22822282
///
22832283
/// [trait object]: ../book/ch17-02-trait-objects.html
2284+
/// [dynamically dispatched]: https://en.wikipedia.org/wiki/Dynamic_dispatch
22842285
/// [ref-trait-obj]: ../reference/types/trait-object.html
22852286
/// [ref-obj-safety]: ../reference/items/traits.html#object-safety
22862287
/// [erased]: https://en.wikipedia.org/wiki/Type_erasure

‎library/std/src/thread/tests.rs

+13
Original file line numberDiff line numberDiff line change
@@ -316,3 +316,16 @@ fn test_scoped_threads_drop_result_before_join() {
316316
});
317317
assert!(actually_finished.load(Ordering::Relaxed));
318318
}
319+
320+
#[test]
321+
fn test_scoped_threads_nll() {
322+
// this is mostly a *compilation test* for this exact function:
323+
fn foo(x: &u8) {
324+
thread::scope(|s| {
325+
s.spawn(|| drop(x));
326+
});
327+
}
328+
// let's also run it for good measure
329+
let x = 42_u8;
330+
foo(&x);
331+
}
+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// compile-flags: --document-private-items --document-hidden-items
2+
3+
// This is a regression test for #98009.
4+
5+
// @has output_generics.json
6+
// @has - "$.index[*][?(@.name=='this_compiles')]"
7+
// @has - "$.index[*][?(@.name=='this_does_not')]"
8+
// @has - "$.index[*][?(@.name=='Events')]"
9+
// @has - "$.index[*][?(@.name=='Other')]"
10+
// @has - "$.index[*][?(@.name=='Trait')]"
11+
12+
struct Events<R>(R);
13+
14+
struct Other;
15+
16+
pub trait Trait<T> {
17+
fn handle(value: T) -> Self;
18+
}
19+
20+
impl<T, U> Trait<U> for T where T: From<U> {
21+
fn handle(_: U) -> Self { unimplemented!() }
22+
}
23+
24+
impl<'a, R> Trait<&'a mut Events<R>> for Other {
25+
fn handle(_: &'a mut Events<R>) -> Self { unimplemented!() }
26+
}
27+
28+
fn this_compiles<'a, R>(value: &'a mut Events<R>) {
29+
for _ in 0..3 {
30+
Other::handle(&mut *value);
31+
}
32+
}
33+
34+
fn this_does_not<'a, R>(value: &'a mut Events<R>) {
35+
for _ in 0..3 {
36+
Other::handle(value);
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// force-host
2+
// no-prefer-dynamic
3+
4+
#![crate_type = "proc-macro"]
5+
6+
extern crate proc_macro;
7+
8+
use proc_macro::TokenStream;
9+
10+
fn compile_error() -> TokenStream {
11+
r#"compile_error!("")"#.parse().unwrap()
12+
}
13+
14+
#[proc_macro_derive(MyTrait)]
15+
pub fn derive(input: TokenStream) -> TokenStream {
16+
compile_error()
17+
}
18+
#[proc_macro_attribute]
19+
pub fn attribute_macro(_attr: TokenStream, mut input: TokenStream) -> TokenStream {
20+
input.extend(compile_error());
21+
input
22+
}
23+
#[proc_macro]
24+
pub fn fn_macro(_item: TokenStream) -> TokenStream {
25+
compile_error()
26+
}

‎src/test/ui/proc-macro/issue-91800.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build: issue-91800-macro.rs
2+
3+
#[macro_use]
4+
extern crate issue_91800_macro;
5+
6+
#[derive(MyTrait)]
7+
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
8+
//~| ERROR proc-macro derive produced unparseable tokens
9+
#[attribute_macro]
10+
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
11+
struct MyStruct;
12+
13+
fn_macro! {}
14+
//~^ ERROR macros that expand to items must be delimited with braces or followed by a semicolon
15+
16+
fn main() {}
+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
error: macros that expand to items must be delimited with braces or followed by a semicolon
2+
--> $DIR/issue-91800.rs:6:10
3+
|
4+
LL | #[derive(MyTrait)]
5+
| ^^^^^^^
6+
|
7+
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
8+
9+
error: proc-macro derive produced unparseable tokens
10+
--> $DIR/issue-91800.rs:6:10
11+
|
12+
LL | #[derive(MyTrait)]
13+
| ^^^^^^^
14+
15+
error:
16+
--> $DIR/issue-91800.rs:6:10
17+
|
18+
LL | #[derive(MyTrait)]
19+
| ^^^^^^^
20+
|
21+
= note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
22+
23+
error: macros that expand to items must be delimited with braces or followed by a semicolon
24+
--> $DIR/issue-91800.rs:9:1
25+
|
26+
LL | #[attribute_macro]
27+
| ^^^^^^^^^^^^^^^^^^
28+
|
29+
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
30+
31+
error:
32+
--> $DIR/issue-91800.rs:9:1
33+
|
34+
LL | #[attribute_macro]
35+
| ^^^^^^^^^^^^^^^^^^
36+
|
37+
= note: this error originates in the attribute macro `attribute_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
38+
39+
error: macros that expand to items must be delimited with braces or followed by a semicolon
40+
--> $DIR/issue-91800.rs:13:1
41+
|
42+
LL | fn_macro! {}
43+
| ^^^^^^^^^^^^
44+
|
45+
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
46+
47+
error:
48+
--> $DIR/issue-91800.rs:13:1
49+
|
50+
LL | fn_macro! {}
51+
| ^^^^^^^^^^^^
52+
|
53+
= note: this error originates in the macro `fn_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
54+
55+
error: aborting due to 7 previous errors
56+

0 commit comments

Comments
 (0)
Please sign in to comment.