Skip to content

Commit dc0943d

Browse files
committed
Auto merge of rust-lang#112055 - matthiaskrgr:rollup-y3exx8c, r=matthiaskrgr
Rollup of 5 pull requests Successful merges: - rust-lang#112029 (Recover upon mistyped error on typo'd `const` in const param def) - rust-lang#112037 (Add details about `unsafe_op_in_unsafe_fn` to E0133) - rust-lang#112039 (compiler: update solaris/illumos to enable tsan support.) - rust-lang#112042 (Migrate GUI colors test to original CSS color format) - rust-lang#112045 (Followup to rust-lang#111973) r? `@ghost` `@rustbot` modify labels: rollup
2 parents f8447b9 + e71b3b3 commit dc0943d

File tree

8 files changed

+135
-11
lines changed

8 files changed

+135
-11
lines changed

compiler/rustc_error_codes/src/error_codes/E0133.md

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Unsafe code was used outside of an unsafe function or block.
1+
Unsafe code was used outside of an unsafe block.
22

33
Erroneous code example:
44

@@ -30,4 +30,21 @@ fn main() {
3030

3131
See the [unsafe section][unsafe-section] of the Book for more details.
3232

33+
#### Unsafe code in functions
34+
35+
Unsafe code is currently accepted in unsafe functions, but that is being phased
36+
out in favor of requiring unsafe blocks here too.
37+
38+
```
39+
unsafe fn f() { return; }
40+
41+
unsafe fn g() {
42+
f(); // Is accepted, but no longer recommended
43+
unsafe { f(); } // Recommended way to write this
44+
}
45+
```
46+
47+
Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
48+
is `allow` by default but will be upgraded to `warn` in a future edition.
49+
3350
[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

compiler/rustc_parse/src/parser/generics.rs

+44
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,15 @@ impl<'a> Parser<'a> {
4343
fn parse_ty_param(&mut self, preceding_attrs: AttrVec) -> PResult<'a, GenericParam> {
4444
let ident = self.parse_ident()?;
4545

46+
// We might have a typo'd `Const` that was parsed as a type parameter.
47+
if self.may_recover()
48+
&& ident.name.as_str().to_ascii_lowercase() == kw::Const.as_str()
49+
&& self.check_ident()
50+
// `Const` followed by IDENT
51+
{
52+
return Ok(self.recover_const_param_with_mistyped_const(preceding_attrs, ident)?);
53+
}
54+
4655
// Parse optional colon and param bounds.
4756
let mut colon_span = None;
4857
let bounds = if self.eat(&token::Colon) {
@@ -120,6 +129,41 @@ impl<'a> Parser<'a> {
120129
})
121130
}
122131

132+
pub(crate) fn recover_const_param_with_mistyped_const(
133+
&mut self,
134+
preceding_attrs: AttrVec,
135+
mistyped_const_ident: Ident,
136+
) -> PResult<'a, GenericParam> {
137+
let ident = self.parse_ident()?;
138+
self.expect(&token::Colon)?;
139+
let ty = self.parse_ty()?;
140+
141+
// Parse optional const generics default value.
142+
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
143+
144+
let mut err = self.struct_span_err(
145+
mistyped_const_ident.span,
146+
format!("`const` keyword was mistyped as `{}`", mistyped_const_ident.as_str()),
147+
);
148+
err.span_suggestion_verbose(
149+
mistyped_const_ident.span,
150+
"use the `const` keyword",
151+
kw::Const.as_str(),
152+
Applicability::MachineApplicable,
153+
);
154+
err.emit();
155+
156+
Ok(GenericParam {
157+
ident,
158+
id: ast::DUMMY_NODE_ID,
159+
attrs: preceding_attrs,
160+
bounds: Vec::new(),
161+
kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default },
162+
is_placeholder: false,
163+
colon_span: None,
164+
})
165+
}
166+
123167
/// Parses a (possibly empty) list of lifetime and type parameters, possibly including
124168
/// a trailing comma and erroneous trailing attributes.
125169
pub(super) fn parse_generic_params(&mut self) -> PResult<'a, ThinVec<ast::GenericParam>> {

compiler/rustc_target/src/spec/x86_64_pc_solaris.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub fn target() -> Target {
77
base.vendor = "pc".into();
88
base.max_atomic_width = Some(64);
99
base.stack_probes = StackProbeType::X86;
10-
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
10+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
1111

1212
Target {
1313
llvm_target: "x86_64-pc-solaris".into(),

compiler/rustc_target/src/spec/x86_64_unknown_illumos.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ pub fn target() -> Target {
55
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64", "-std=c99"]);
66
base.cpu = "x86-64".into();
77
base.max_atomic_width = Some(64);
8-
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
8+
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
99

1010
Target {
1111
// LLVM does not currently have a separate illumos target,

library/core/src/slice/mod.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -3113,8 +3113,9 @@ impl<T> [T] {
31133113
///
31143114
/// # Current implementation
31153115
///
3116-
/// The current algorithm is based on the quickselect portion of the same quicksort algorithm
3117-
/// used for [`sort_unstable`].
3116+
/// The current algorithm is an introselect implementation based on Pattern Defeating Quicksort, which is also
3117+
/// the basis for [`sort_unstable`]. The fallback algorithm is Median of Medians using Tukey's Ninther for
3118+
/// pivot selection, which guarantees linear runtime for all inputs.
31183119
///
31193120
/// [`sort_unstable`]: slice::sort_unstable
31203121
///

tests/rustdoc-gui/search-result-display.goml

+6-6
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ define-function: (
5757

5858
call-function: ("check-filter", {
5959
"theme": "ayu",
60-
"border": "rgb(92, 103, 115)",
60+
"border": "#5c6773",
6161
"filter": "invert(0.41) sepia(0.12) saturate(4.87) hue-rotate(171deg) brightness(0.94) contrast(0.94)",
62-
"hover_border": "rgb(224, 224, 224)",
62+
"hover_border": "#e0e0e0",
6363
"hover_filter": "invert(0.98) sepia(0.12) saturate(0.81) hue-rotate(343deg) brightness(1.13) contrast(0.76)",
6464
})
6565
call-function: ("check-filter", {
6666
"theme": "dark",
67-
"border": "rgb(224, 224, 224)",
67+
"border": "#e0e0e0",
6868
"filter": "invert(0.94) sepia(0) saturate(7.21) hue-rotate(255deg) brightness(0.9) contrast(0.9)",
69-
"hover_border": "rgb(33, 150, 243)",
69+
"hover_border": "#2196f3",
7070
"hover_filter": "invert(0.69) sepia(0.6) saturate(66.13) hue-rotate(184deg) brightness(1) contrast(0.91)",
7171
})
7272
call-function: ("check-filter", {
7373
"theme": "light",
74-
"border": "rgb(224, 224, 224)",
74+
"border": "#e0e0e0",
7575
"filter": "invert(1) sepia(0) saturate(42.23) hue-rotate(289deg) brightness(1.14) contrast(0.76)",
76-
"hover_border": "rgb(113, 113, 113)",
76+
"hover_border": "#717171",
7777
"hover_filter": "invert(0.44) sepia(0.18) saturate(0.23) hue-rotate(317deg) brightness(0.96) contrast(0.93)",
7878
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pub fn foo<Const N: u8>() {}
2+
//~^ ERROR `const` keyword was mistyped as `Const`
3+
4+
pub fn bar<Const>() {}
5+
// OK
6+
7+
pub fn baz<Const N: u8, T>() {}
8+
//~^ ERROR `const` keyword was mistyped as `Const`
9+
10+
pub fn qux<T, Const N: u8>() {}
11+
//~^ ERROR `const` keyword was mistyped as `Const`
12+
13+
pub fn quux<T, Const N: u8, U>() {}
14+
//~^ ERROR `const` keyword was mistyped as `Const`
15+
16+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
error: `const` keyword was mistyped as `Const`
2+
--> $DIR/typod-const-in-const-param-def.rs:1:12
3+
|
4+
LL | pub fn foo<Const N: u8>() {}
5+
| ^^^^^
6+
|
7+
help: use the `const` keyword
8+
|
9+
LL | pub fn foo<const N: u8>() {}
10+
| ~~~~~
11+
12+
error: `const` keyword was mistyped as `Const`
13+
--> $DIR/typod-const-in-const-param-def.rs:7:12
14+
|
15+
LL | pub fn baz<Const N: u8, T>() {}
16+
| ^^^^^
17+
|
18+
help: use the `const` keyword
19+
|
20+
LL | pub fn baz<const N: u8, T>() {}
21+
| ~~~~~
22+
23+
error: `const` keyword was mistyped as `Const`
24+
--> $DIR/typod-const-in-const-param-def.rs:10:15
25+
|
26+
LL | pub fn qux<T, Const N: u8>() {}
27+
| ^^^^^
28+
|
29+
help: use the `const` keyword
30+
|
31+
LL | pub fn qux<T, const N: u8>() {}
32+
| ~~~~~
33+
34+
error: `const` keyword was mistyped as `Const`
35+
--> $DIR/typod-const-in-const-param-def.rs:13:16
36+
|
37+
LL | pub fn quux<T, Const N: u8, U>() {}
38+
| ^^^^^
39+
|
40+
help: use the `const` keyword
41+
|
42+
LL | pub fn quux<T, const N: u8, U>() {}
43+
| ~~~~~
44+
45+
error: aborting due to 4 previous errors
46+

0 commit comments

Comments
 (0)