Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -833,12 +833,13 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {

// const-eval of `panic_display` assumes the argument is `&&str`
if tcx.is_lang_item(callee, LangItem::PanicDisplay) {
match args[0].node.ty(&self.ccx.body.local_decls, tcx).kind() {
ty::Ref(_, ty, _) if matches!(ty.kind(), ty::Ref(_, ty, _) if ty.is_str()) =>
{}
_ => {
self.check_op(ops::PanicNonStr);
}
if let ty::Ref(_, ty, _) =
args[0].node.ty(&self.ccx.body.local_decls, tcx).kind()
&& let ty::Ref(_, ty, _) = ty.kind()
&& ty.is_str()
{
} else {
self.check_op(ops::PanicNonStr);
}
// Allow this call, skip all the checks below.
return;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/early/diagnostics/check_cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn cargo_help_sub(
// `build_script_build`) to try to figure out if we are building a Cargo build script

let unescaped = &inst(EscapeQuotes::No);
if matches!(&sess.opts.crate_name, Some(crate_name) if crate_name == "build_script_build") {
if let Some("build_script_build") = sess.opts.crate_name.as_deref() {
lints::UnexpectedCfgCargoHelp::lint_cfg(unescaped)
} else {
lints::UnexpectedCfgCargoHelp::lint_cfg_and_build_rs(unescaped, &inst(EscapeQuotes::Yes))
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/transmute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,9 @@ fn check_int_to_ptr_transmute<'tcx>(
return;
};
// bail-out if the argument is literal 0 as we have other lints for those cases
if matches!(arg.kind, hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) if v == 0) {
if let hir::ExprKind::Lit(hir::Lit { node: LitKind::Int(v, _), .. }) = arg.kind
&& v == 0
{
return;
}
// bail-out if the inner type is a ZST
Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/mir/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1871,13 +1871,16 @@ fn pretty_print_const_value_tcx<'tcx>(
let u8_type = tcx.types.u8;
match (ct, ty.kind()) {
// Byte/string slices, printed as (byte) string literals.
(_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Str) => {
(_, ty::Ref(_, inner_ty, _)) if let ty::Str = inner_ty.kind() => {
if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) {
fmt.write_str(&format!("{:?}", String::from_utf8_lossy(data)))?;
return Ok(());
}
}
(_, ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(t) if *t == u8_type) => {
(_, ty::Ref(_, inner_ty, _))
if let ty::Slice(t) = inner_ty.kind()
&& *t == u8_type =>
{
if let Some(data) = ct.try_get_slice_bytes_for_diagnostics(tcx) {
pretty_print_byte_str(fmt, data)?;
return Ok(());
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_parse/src/parser/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,9 @@ impl<'a> Parser<'a> {
}

// Check for misspelled keywords if there are no suggestions added to the diagnostic.
if matches!(&err.suggestions, Suggestions::Enabled(list) if list.is_empty()) {
if let Suggestions::Enabled(list) = &err.suggestions
&& list.is_empty()
{
self.check_for_misspelled_kw(&mut err, &expected);
}
Err(err)
Expand Down
7 changes: 3 additions & 4 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,9 @@ impl<'a> Parser<'a> {
let mut token = Token::dummy();
while i < dist {
token = cursor.next().0;
if matches!(
token.kind,
token::OpenInvisible(origin) | token::CloseInvisible(origin) if origin.skip()
) {
if let token::OpenInvisible(origin) | token::CloseInvisible(origin) = token.kind
&& origin.skip()
{
continue;
}
i += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4722,7 +4722,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
// slices of `element_ty` with `mutability`.
let mut is_slice = |candidate: Ty<'tcx>| match *candidate.kind() {
ty::RawPtr(t, m) | ty::Ref(_, t, m) => {
if matches!(*t.kind(), ty::Slice(e) if e == element_ty)
if let ty::Slice(e) = *t.kind()
&& e == element_ty
&& m == mutability.unwrap_or(m)
{
// Use the candidate's mutability going forward.
Expand Down
Loading