1
Fork 0

Auto merge of #112055 - matthiaskrgr:rollup-y3exx8c, r=matthiaskrgr

Rollup of 5 pull requests

Successful merges:

 - #112029 (Recover upon mistyped error on typo'd `const` in const param def)
 - #112037 (Add details about `unsafe_op_in_unsafe_fn` to E0133)
 - #112039 (compiler: update solaris/illumos to enable tsan support.)
 - #112042 (Migrate GUI colors test to original CSS color format)
 - #112045 (Followup to #111973)

r? `@ghost`
`@rustbot` modify labels: rollup
This commit is contained in:
bors 2023-05-29 03:04:06 +00:00
commit dc0943d2ee
8 changed files with 135 additions and 11 deletions

View file

@ -1,4 +1,4 @@
Unsafe code was used outside of an unsafe function or block.
Unsafe code was used outside of an unsafe block.
Erroneous code example:
@ -30,4 +30,21 @@ fn main() {
See the [unsafe section][unsafe-section] of the Book for more details.
#### Unsafe code in functions
Unsafe code is currently accepted in unsafe functions, but that is being phased
out in favor of requiring unsafe blocks here too.
```
unsafe fn f() { return; }
unsafe fn g() {
f(); // Is accepted, but no longer recommended
unsafe { f(); } // Recommended way to write this
}
```
Linting against this is controlled via the `unsafe_op_in_unsafe_fn` lint, which
is `allow` by default but will be upgraded to `warn` in a future edition.
[unsafe-section]: https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html

View file

@ -43,6 +43,15 @@ impl<'a> Parser<'a> {
fn parse_ty_param(&mut self, preceding_attrs: AttrVec) -> PResult<'a, GenericParam> {
let ident = self.parse_ident()?;
// We might have a typo'd `Const` that was parsed as a type parameter.
if self.may_recover()
&& ident.name.as_str().to_ascii_lowercase() == kw::Const.as_str()
&& self.check_ident()
// `Const` followed by IDENT
{
return Ok(self.recover_const_param_with_mistyped_const(preceding_attrs, ident)?);
}
// Parse optional colon and param bounds.
let mut colon_span = None;
let bounds = if self.eat(&token::Colon) {
@ -120,6 +129,41 @@ impl<'a> Parser<'a> {
})
}
pub(crate) fn recover_const_param_with_mistyped_const(
&mut self,
preceding_attrs: AttrVec,
mistyped_const_ident: Ident,
) -> PResult<'a, GenericParam> {
let ident = self.parse_ident()?;
self.expect(&token::Colon)?;
let ty = self.parse_ty()?;
// Parse optional const generics default value.
let default = if self.eat(&token::Eq) { Some(self.parse_const_arg()?) } else { None };
let mut err = self.struct_span_err(
mistyped_const_ident.span,
format!("`const` keyword was mistyped as `{}`", mistyped_const_ident.as_str()),
);
err.span_suggestion_verbose(
mistyped_const_ident.span,
"use the `const` keyword",
kw::Const.as_str(),
Applicability::MachineApplicable,
);
err.emit();
Ok(GenericParam {
ident,
id: ast::DUMMY_NODE_ID,
attrs: preceding_attrs,
bounds: Vec::new(),
kind: GenericParamKind::Const { ty, kw_span: mistyped_const_ident.span, default },
is_placeholder: false,
colon_span: None,
})
}
/// Parses a (possibly empty) list of lifetime and type parameters, possibly including
/// a trailing comma and erroneous trailing attributes.
pub(super) fn parse_generic_params(&mut self) -> PResult<'a, ThinVec<ast::GenericParam>> {

View file

@ -7,7 +7,7 @@ pub fn target() -> Target {
base.vendor = "pc".into();
base.max_atomic_width = Some(64);
base.stack_probes = StackProbeType::X86;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
Target {
llvm_target: "x86_64-pc-solaris".into(),

View file

@ -5,7 +5,7 @@ pub fn target() -> Target {
base.add_pre_link_args(LinkerFlavor::Unix(Cc::Yes), &["-m64", "-std=c99"]);
base.cpu = "x86-64".into();
base.max_atomic_width = Some(64);
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI;
base.supported_sanitizers = SanitizerSet::ADDRESS | SanitizerSet::CFI | SanitizerSet::THREAD;
Target {
// LLVM does not currently have a separate illumos target,