Skip to content

Commit f466f52

Browse files
committed
Auto merge of #65716 - JohnTitor:rollup-fkcr85k, r=JohnTitor
Rollup of 14 pull requests Successful merges: - #64145 (Target-feature documented as unsafe) - #65007 (Mention keyword closing policy) - #65417 (Add more coherence tests) - #65507 (Fix test style in unused parentheses lint test) - #65591 (Add long error explanation for E0588) - #65617 (Fix WASI sleep impl) - #65656 (Add option to disable keyboard shortcuts in docs) - #65678 (Add long error explanation for E0728) - #65681 (Code cleanups following up on #65576.) - #65686 (refactor and move `maybe_append` ) - #65688 (Add some tests for fixed ICEs) - #65689 (bring back some Debug instances for Miri) - #65695 (self-profiling: Remove module names from some event-ids in codegen backend.) - #65706 (Add missing space in librustdoc) Failed merges: r? @ghost
2 parents d6e4028 + 1df9081 commit f466f52

File tree

58 files changed

+744
-803
lines changed

Some content is hidden

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

58 files changed

+744
-803
lines changed

CONTRIBUTING.md

+8
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,14 @@ the master branch to your feature branch.
128128
Also, please make sure that fixup commits are squashed into other related
129129
commits with meaningful commit messages.
130130

131+
GitHub allows [closing issues using keywords][closing-keywords]. This feature
132+
should be used to keep the issue tracker tidy. However, it is generally preferred
133+
to put the "closes #123" text in the PR description rather than the issue commit;
134+
particularly during rebasing, citing the issue number in the commit can "spam"
135+
the issue in question.
136+
137+
[closing-keywords]: https://help.github.com/en/articles/closing-issues-using-keywords
138+
131139
Please make sure your pull request is in compliance with Rust's style
132140
guidelines by running
133141

src/doc/rustc/src/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
- [Targets](targets/index.md)
1515
- [Built-in Targets](targets/built-in.md)
1616
- [Custom Targets](targets/custom.md)
17+
- [Known Issues](targets/known-issues.md)
1718
- [Profile-guided Optimization](profile-guided-optimization.md)
1819
- [Linker-plugin based LTO](linker-plugin-lto.md)
1920
- [Contributing to `rustc`](contributing.md)

src/doc/rustc/src/codegen-options/index.md

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ enabling or disabling a feature.
6161
To see the valid options and an example of use, run `rustc --print
6262
target-features`.
6363

64+
Using this flag is unsafe and might result in [undefined runtime behavior](../targets/known-issues.md).
65+
6466
## passes
6567

6668
This flag can be used to add extra LLVM passes to the compilation.

src/doc/rustc/src/command-line-arguments.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ of print values are:
145145
target CPU may be selected with the `-C target-cpu=val` flag.
146146
- `target-features` — List of available target features for the current
147147
target. Target features may be enabled with the `-C target-feature=val`
148-
flag.
148+
flag. This flag is unsafe. See [known issues](targets/known-issues.md) for more details.
149149
- `relocation-models` — List of relocation models. Relocation models may be
150150
selected with the `-C relocation-model=val` flag.
151151
- `code-models` — List of code models. Code models may be selected with the

src/doc/rustc/src/targets/index.md

+6
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,9 @@ To compile to a particular target, use the `--target` flag:
1111
```bash
1212
$ rustc src/main.rs --target=wasm32-unknown-unknown
1313
```
14+
## Target Features
15+
`x86`, and `ARMv8` are two popular CPU architectures. Their instruction sets form a common baseline across most CPUs. However, some CPUs extend these with custom instruction sets, e.g. vector (`AVX`), bitwise manipulation (`BMI`) or cryptographic (`AES`).
16+
17+
Developers, who know on which CPUs their compiled code is going to run can choose to add (or remove) CPU specific instruction sets via the `-C target-feature=val` flag.
18+
19+
Please note, that this flag is generally considered as unsafe. More details can be found in [this section](known-issues.md).
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Known Issues
2+
This section informs you about known "gotchas". Keep in mind, that this section is (and always will be) incomplete. For suggestions and amendments, feel free to [contribute](../contributing.md) to this guide.
3+
4+
## Target Features
5+
Most target-feature problems arise, when mixing code that have the target-feature _enabled_ with code that have it _disabled_. If you want to avoid undefined behavior, it is recommended to build _all code_ (including the standard library and imported crates) with a common set of target-features.
6+
7+
By default, compiling your code with the `-C target-feature` flag will not recompile the entire standard library and/or imported crates with matching target features. Therefore, target features are generally considered as unsafe. Using `#[target_feature]` on individual functions makes the function unsafe.
8+
9+
Examples:
10+
11+
| Target-Feature | Issue | Seen on | Description | Details |
12+
| -------------- | ----- | ------- | ----------- | ------- |
13+
| `+soft-float` <br> and <br> `-sse` | Segfaults and ABI mismatches | `x86` and `x86-64` | The `x86` and `x86_64` architecture uses SSE registers (aka `xmm`) for floating point operations. Using software emulated floats ("soft-floats") disables usage of `xmm` registers, but parts of Rust's core libraries (e.g. `std::f32` or `std::f64`) are compiled without soft-floats and expect parameters to be passed in `xmm` registers. This leads to ABI mismatches. <br><br> Attempting to compile with disabled SSE causes the same error, too. | [#63466](https://github.com/rust-lang/rust/issues/63466) |

src/librustc/error_codes.rs

+80-3
Original file line numberDiff line numberDiff line change
@@ -2045,8 +2045,8 @@ so that a generator can then be constructed:
20452045
async fn bar<T>() -> () {}
20462046
20472047
async fn foo() {
2048-
bar::<String>().await;
2049-
// ^^^^^^^^ specify type explicitly
2048+
bar::<String>().await;
2049+
// ^^^^^^^^ specify type explicitly
20502050
}
20512051
```
20522052
"##,
@@ -2126,6 +2126,84 @@ static X: u32 = 42;
21262126
```
21272127
"##,
21282128

2129+
E0728: r##"
2130+
[`await`] has been used outside [`async`] function or block.
2131+
2132+
Erroneous code examples:
2133+
2134+
```edition2018,compile_fail,E0728
2135+
# use std::pin::Pin;
2136+
# use std::future::Future;
2137+
# use std::task::{Context, Poll};
2138+
#
2139+
# struct WakeOnceThenComplete(bool);
2140+
#
2141+
# fn wake_and_yield_once() -> WakeOnceThenComplete {
2142+
# WakeOnceThenComplete(false)
2143+
# }
2144+
#
2145+
# impl Future for WakeOnceThenComplete {
2146+
# type Output = ();
2147+
# fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
2148+
# if self.0 {
2149+
# Poll::Ready(())
2150+
# } else {
2151+
# cx.waker().wake_by_ref();
2152+
# self.0 = true;
2153+
# Poll::Pending
2154+
# }
2155+
# }
2156+
# }
2157+
#
2158+
fn foo() {
2159+
wake_and_yield_once().await // `await` is used outside `async` context
2160+
}
2161+
```
2162+
2163+
[`await`] is used to suspend the current computation until the given
2164+
future is ready to produce a value. So it is legal only within
2165+
an [`async`] context, like an `async fn` or an `async` block.
2166+
2167+
```edition2018
2168+
# use std::pin::Pin;
2169+
# use std::future::Future;
2170+
# use std::task::{Context, Poll};
2171+
#
2172+
# struct WakeOnceThenComplete(bool);
2173+
#
2174+
# fn wake_and_yield_once() -> WakeOnceThenComplete {
2175+
# WakeOnceThenComplete(false)
2176+
# }
2177+
#
2178+
# impl Future for WakeOnceThenComplete {
2179+
# type Output = ();
2180+
# fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
2181+
# if self.0 {
2182+
# Poll::Ready(())
2183+
# } else {
2184+
# cx.waker().wake_by_ref();
2185+
# self.0 = true;
2186+
# Poll::Pending
2187+
# }
2188+
# }
2189+
# }
2190+
#
2191+
async fn foo() {
2192+
wake_and_yield_once().await // `await` is used within `async` function
2193+
}
2194+
2195+
fn bar(x: u8) -> impl Future<Output = u8> {
2196+
async move {
2197+
wake_and_yield_once().await; // `await` is used within `async` block
2198+
x
2199+
}
2200+
}
2201+
```
2202+
2203+
[`async`]: https://doc.rust-lang.org/std/keyword.async.html
2204+
[`await`]: https://doc.rust-lang.org/std/keyword.await.html
2205+
"##,
2206+
21292207
E0734: r##"
21302208
A stability attribute has been used outside of the standard library.
21312209
@@ -2218,6 +2296,5 @@ See [RFC 2091] for details on this and other limitations.
22182296
// E0702, // replaced with a generic attribute input check
22192297
E0726, // non-explicit (not `'_`) elided lifetime in unsupported position
22202298
E0727, // `async` generators are not yet supported
2221-
E0728, // `await` must be in an `async` function or block
22222299
E0739, // invalid track_caller application/syntax
22232300
}

src/librustc/session/config.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1149,7 +1149,8 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
11491149
target_cpu: Option<String> = (None, parse_opt_string, [TRACKED],
11501150
"select target processor (`rustc --print target-cpus` for details)"),
11511151
target_feature: String = (String::new(), parse_string, [TRACKED],
1152-
"target specific attributes (`rustc --print target-features` for details)"),
1152+
"target specific attributes. (`rustc --print target-features` for details). \
1153+
This feature is unsafe."),
11531154
passes: Vec<String> = (Vec::new(), parse_list, [TRACKED],
11541155
"a list of extra LLVM passes to run (space separated)"),
11551156
llvm_args: Vec<String> = (Vec::new(), parse_list, [TRACKED],

src/librustc_codegen_ssa/back/write.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ fn generate_lto_work<B: ExtraBackendMethods>(
259259
needs_thin_lto: Vec<(String, B::ThinBuffer)>,
260260
import_only_modules: Vec<(SerializedModule<B::ModuleBuffer>, WorkProduct)>
261261
) -> Vec<(WorkItem<B>, u64)> {
262-
let _prof_timer = cgcx.prof.generic_activity("codegen_run_lto");
262+
let _prof_timer = cgcx.prof.generic_activity("codegen_generate_lto_work");
263263

264264
let (lto_modules, copy_jobs) = if !needs_fat_lto.is_empty() {
265265
assert!(needs_thin_lto.is_empty());
@@ -674,11 +674,11 @@ impl<B: WriteBackendMethods> WorkItem<B> {
674674
}
675675
}
676676

677-
pub fn name(&self) -> String {
677+
fn profiling_event_id(&self) -> &'static str {
678678
match *self {
679-
WorkItem::Optimize(ref m) => format!("optimize: {}", m.name),
680-
WorkItem::CopyPostLtoArtifacts(ref m) => format!("copy post LTO artifacts: {}", m.name),
681-
WorkItem::LTO(ref m) => format!("lto: {}", m.name()),
679+
WorkItem::Optimize(_) => "codegen_module_optimize",
680+
WorkItem::CopyPostLtoArtifacts(_) => "codegen_copy_artifacts_from_incr_cache",
681+
WorkItem::LTO(_) => "codegen_module_perform_lto",
682682
}
683683
}
684684
}
@@ -1587,7 +1587,7 @@ fn spawn_work<B: ExtraBackendMethods>(
15871587
// as a diagnostic was already sent off to the main thread - just
15881588
// surface that there was an error in this worker.
15891589
bomb.result = {
1590-
let _prof_timer = cgcx.prof.generic_activity(&work.name());
1590+
let _prof_timer = cgcx.prof.generic_activity(work.profiling_event_id());
15911591
execute_work_item(&cgcx, work).ok()
15921592
};
15931593
});

src/librustc_codegen_ssa/base.rs

+24-13
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
406406
rust_main_def_id: DefId,
407407
use_start_lang_item: bool,
408408
) {
409+
// The entry function is either `int main(void)` or `int main(int argc, char **argv)`,
410+
// depending on whether the target needs `argc` and `argv` to be passed in.
409411
let llfty = if cx.sess().target.target.options.main_needs_argc_argv {
410412
cx.type_func(&[cx.type_int(), cx.type_ptr_to(cx.type_i8p())], cx.type_int())
411413
} else {
@@ -440,19 +442,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
440442

441443
bx.insert_reference_to_gdb_debug_scripts_section_global();
442444

443-
let (arg_argc, arg_argv) = if cx.sess().target.target.options.main_needs_argc_argv {
444-
// Params from native main() used as args for rust start function
445-
let param_argc = bx.get_param(0);
446-
let param_argv = bx.get_param(1);
447-
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true);
448-
let arg_argv = param_argv;
449-
(arg_argc, arg_argv)
450-
} else {
451-
// The Rust start function doesn't need argc and argv, so just pass zeros.
452-
let arg_argc = bx.const_int(cx.type_int(), 0);
453-
let arg_argv = bx.const_null(cx.type_ptr_to(cx.type_i8p()));
454-
(arg_argc, arg_argv)
455-
};
445+
let (arg_argc, arg_argv) = get_argc_argv(cx, &mut bx);
456446

457447
let (start_fn, args) = if use_start_lang_item {
458448
let start_def_id = cx.tcx().require_lang_item(StartFnLangItem, None);
@@ -477,6 +467,27 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(cx: &'
477467
}
478468
}
479469

470+
/// Obtain the `argc` and `argv` values to pass to the rust start function.
471+
fn get_argc_argv<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
472+
cx: &'a Bx::CodegenCx,
473+
bx: &mut Bx
474+
) -> (Bx::Value, Bx::Value)
475+
{
476+
if cx.sess().target.target.options.main_needs_argc_argv {
477+
// Params from native `main()` used as args for rust start function
478+
let param_argc = bx.get_param(0);
479+
let param_argv = bx.get_param(1);
480+
let arg_argc = bx.intcast(param_argc, cx.type_isize(), true);
481+
let arg_argv = param_argv;
482+
(arg_argc, arg_argv)
483+
} else {
484+
// The Rust start function doesn't need `argc` and `argv`, so just pass zeros.
485+
let arg_argc = bx.const_int(cx.type_int(), 0);
486+
let arg_argv = bx.const_null(cx.type_ptr_to(cx.type_i8p()));
487+
(arg_argc, arg_argv)
488+
}
489+
}
490+
480491
pub const CODEGEN_WORKER_ID: usize = ::std::usize::MAX;
481492

482493
pub fn codegen_crate<B: ExtraBackendMethods>(

src/librustc_mir/interpret/eval_context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub struct Frame<'mir, 'tcx, Tag=(), Extra=()> {
9191
pub extra: Extra,
9292
}
9393

94-
#[derive(Clone, Eq, PartialEq)]
94+
#[derive(Clone, Eq, PartialEq, Debug)] // Miri debug-prints these
9595
pub enum StackPopCleanup {
9696
/// Jump to the next block in the caller, or cause UB if None (that's a function
9797
/// that may never return). Also store layout of return place so
@@ -113,7 +113,7 @@ pub struct LocalState<'tcx, Tag=(), Id=AllocId> {
113113
}
114114

115115
/// Current value of a local variable
116-
#[derive(Clone, PartialEq, Eq)]
116+
#[derive(Clone, PartialEq, Eq, Debug)] // Miri debug-prints these
117117
pub enum LocalValue<Tag=(), Id=AllocId> {
118118
/// This local is not currently alive, and cannot be used at all.
119119
Dead,

src/librustc_typeck/error_codes.rs

+32-6
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ a guard.
194194
```compile_fail,E0029
195195
let string = "salutations !";
196196
197-
// The ordering relation for strings can't be evaluated at compile time,
197+
// The ordering relation for strings cannot be evaluated at compile time,
198198
// so this doesn't work:
199199
match string {
200200
"hello" ..= "world" => {}
@@ -348,7 +348,7 @@ fn main() {
348348
"##,
349349

350350
E0044: r##"
351-
You can't use type or const parameters on foreign items.
351+
You cannot use type or const parameters on foreign items.
352352
Example of erroneous code:
353353
354354
```compile_fail,E0044
@@ -788,7 +788,7 @@ fn some_other_func() {}
788788
fn some_function() {
789789
SOME_CONST = 14; // error : a constant value cannot be changed!
790790
1 = 3; // error : 1 isn't a valid place!
791-
some_other_func() = 4; // error : we can't assign value to a function!
791+
some_other_func() = 4; // error : we cannot assign value to a function!
792792
SomeStruct.x = 12; // error : SomeStruct a structure name but it is used
793793
// like a variable!
794794
}
@@ -3891,6 +3891,33 @@ details.
38913891
[issue #33685]: https://github.com/rust-lang/rust/issues/33685
38923892
"##,
38933893

3894+
E0588: r##"
3895+
A type with `packed` representation hint has a field with `align`
3896+
representation hint.
3897+
3898+
Erroneous code example:
3899+
3900+
```compile_fail,E0588
3901+
#[repr(align(16))]
3902+
struct Aligned(i32);
3903+
3904+
#[repr(packed)] // error!
3905+
struct Packed(Aligned);
3906+
```
3907+
3908+
Just like you cannot have both `align` and `packed` representation hints on a
3909+
same type, a `packed` type cannot contain another type with the `align`
3910+
representation hint. However, you can do the opposite:
3911+
3912+
```
3913+
#[repr(packed)]
3914+
struct Packed(i32);
3915+
3916+
#[repr(align(16))] // ok!
3917+
struct Aligned(Packed);
3918+
```
3919+
"##,
3920+
38943921
E0592: r##"
38953922
This error occurs when you defined methods or associated functions with same
38963923
name.
@@ -4299,7 +4326,7 @@ extern {
42994326
43004327
unsafe {
43014328
printf(::std::ptr::null(), 0f32);
4302-
// error: can't pass an `f32` to variadic function, cast to `c_double`
4329+
// error: cannot pass an `f32` to variadic function, cast to `c_double`
43034330
}
43044331
```
43054332
@@ -5000,7 +5027,7 @@ the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
50005027
// E0174,
50015028
// E0182, // merged into E0229
50025029
E0183,
5003-
// E0187, // can't infer the kind of the closure
5030+
// E0187, // cannot infer the kind of the closure
50045031
// E0188, // can not cast an immutable reference to a mutable pointer
50055032
// E0189, // deprecated: can only cast a boxed pointer to a boxed object
50065033
// E0190, // deprecated: can only cast a &-pointer to an &-object
@@ -5047,7 +5074,6 @@ the future, [RFC 2091] prohibits their implementation without a follow-up RFC.
50475074
// E0564, // only named lifetimes are allowed in `impl Trait`,
50485075
// but `{}` was found in the type `{}`
50495076
E0587, // type has conflicting packed and align representation hints
5050-
E0588, // packed type cannot transitively contain a `[repr(align)]` type
50515077
// E0611, // merged into E0616
50525078
// E0612, // merged into E0609
50535079
// E0613, // Removed (merged with E0609)

src/librustdoc/doctree.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Module<'hir> {
5959
fns : Vec::new(),
6060
mods : Vec::new(),
6161
typedefs : Vec::new(),
62-
opaque_tys : Vec::new(),
62+
opaque_tys : Vec::new(),
6363
statics : Vec::new(),
6464
constants : Vec::new(),
6565
traits : Vec::new(),

src/librustdoc/html/render.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,7 @@ fn settings(root_path: &str, suffix: &str) -> String {
12411241
("go-to-only-result", "Directly go to item in search if there is only one result",
12421242
false),
12431243
("line-numbers", "Show line numbers on code examples", false),
1244+
("disable-shortcuts", "Disable keyboard shortcuts", false),
12441245
];
12451246
format!(
12461247
"<h1 class='fqn'>\

0 commit comments

Comments
 (0)