Skip to content

Commit 2627e9f

Browse files
committed
Auto merge of rust-lang#122822 - matthiaskrgr:rollup-rjgmnbe, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#122222 (deref patterns: bare-bones feature gate and typechecking) - rust-lang#122358 (Don't ICE when encountering bound regions in generator interior type) - rust-lang#122696 (Add bare metal riscv32 target.) - rust-lang#122773 (make "expected paren or brace" error translatable) - rust-lang#122795 (Inherit `RUSTC_BOOTSTRAP` when testing wasm) - rust-lang#122799 (Replace closures with `_` when suggesting fully qualified path for method call) - rust-lang#122801 (Fix misc printing issues in emit=stable_mir) - rust-lang#122806 (Make `type_ascribe!` not a built-in) Failed merges: - rust-lang#122771 (add some comments to hir::ModuleItems) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 03994e4 + 62e414d commit 2627e9f

File tree

60 files changed

+751
-719
lines changed

Some content is hidden

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

60 files changed

+751
-719
lines changed

compiler/rustc_ast_passes/src/feature_gate.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
413413
}
414414
}
415415
PatKind::Box(..) => {
416-
gate!(&self, box_patterns, pattern.span, "box pattern syntax is experimental");
416+
if !self.features.deref_patterns {
417+
// Allow box patterns under `deref_patterns`.
418+
gate!(&self, box_patterns, pattern.span, "box pattern syntax is experimental");
419+
}
417420
}
418421
PatKind::Range(_, Some(_), Spanned { node: RangeEnd::Excluded, .. }) => {
419422
gate!(
@@ -607,13 +610,16 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
607610
};
608611
}
609612

613+
if !visitor.features.deref_patterns {
614+
// Allow box patterns under `deref_patterns`.
615+
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
616+
}
610617
gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
611618
// Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now,
612619
// used to be gated under associated_type_bounds, which are right above, so RTN needs to
613620
// be too.
614621
gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental");
615622
gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
616-
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
617623
gate_all_legacy_dont_use!(
618624
exclusive_range_pattern,
619625
"exclusive range pattern syntax is experimental"

compiler/rustc_builtin_macros/src/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ mod log_syntax;
4949
mod source_util;
5050
mod test;
5151
mod trace_macros;
52-
mod type_ascribe;
5352
mod util;
5453

5554
pub mod asm;
@@ -99,7 +98,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
9998
std_panic: edition_panic::expand_panic,
10099
stringify: source_util::expand_stringify,
101100
trace_macros: trace_macros::expand_trace_macros,
102-
type_ascribe: type_ascribe::expand_type_ascribe,
103101
unreachable: edition_panic::expand_unreachable,
104102
// tidy-alphabetical-end
105103
}

compiler/rustc_builtin_macros/src/type_ascribe.rs

-35
This file was deleted.

compiler/rustc_expand/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding
3333
expand_expected_comma_in_list =
3434
expected token: `,`
3535
36+
expand_expected_paren_or_brace =
37+
expected `(` or `{"{"}`, found `{$token}`
38+
3639
expand_explain_doc_comment_inner =
3740
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
3841

compiler/rustc_expand/src/errors.rs

+8
Original file line numberDiff line numberDiff line change
@@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier {
448448
pub fragment: Ident,
449449
pub help: String,
450450
}
451+
452+
#[derive(Diagnostic)]
453+
#[diag(expand_expected_paren_or_brace)]
454+
pub struct ExpectedParenOrBrace<'a> {
455+
#[primary_span]
456+
pub span: Span,
457+
pub token: Cow<'a, str>,
458+
}

compiler/rustc_expand/src/mbe/quoted.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,11 @@ fn parse_tree<'a>(
194194
}
195195
Delimiter::Parenthesis => {}
196196
_ => {
197-
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
198-
let msg = format!("expected `(` or `{{`, found `{tok}`");
199-
sess.dcx().span_err(delim_span.entire(), msg);
197+
let token = pprust::token_kind_to_string(&token::OpenDelim(delim));
198+
sess.dcx().emit_err(errors::ExpectedParenOrBrace {
199+
span: delim_span.entire(),
200+
token,
201+
});
200202
}
201203
}
202204
}

compiler/rustc_feature/src/unstable.rs

+2
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,8 @@ declare_features! (
436436
(unstable, deprecated_safe, "1.61.0", Some(94978)),
437437
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
438438
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
439+
/// Allows deref patterns.
440+
(incomplete, deref_patterns, "CURRENT_RUSTC_VERSION", Some(87121)),
439441
/// Controls errors in trait implementations.
440442
(unstable, do_not_recommend, "1.67.0", Some(51992)),
441443
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_hir_analysis/src/astconv/bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ fn check_assoc_const_binding_type<'tcx>(
565565
let mut guar = ty.visit_with(&mut collector).break_value();
566566

567567
let ty_note = ty
568-
.make_suggestable(tcx, false)
568+
.make_suggestable(tcx, false, None)
569569
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });
570570

571571
let enclosing_item_owner_id = tcx

compiler/rustc_hir_analysis/src/collect.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1371,7 +1371,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
13711371
// recursive function definition to leak out into the fn sig.
13721372
let mut should_recover = false;
13731373

1374-
if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false) {
1374+
if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false, None) {
13751375
diag.span_suggestion(
13761376
ty.span,
13771377
"replace with the correct return type",
@@ -1449,7 +1449,7 @@ fn suggest_impl_trait<'tcx>(
14491449
let ty::Tuple(types) = *args_tuple.kind() else {
14501450
return None;
14511451
};
1452-
let types = types.make_suggestable(tcx, false)?;
1452+
let types = types.make_suggestable(tcx, false, None)?;
14531453
let maybe_ret =
14541454
if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") };
14551455
Some(format!(
@@ -1507,7 +1507,7 @@ fn suggest_impl_trait<'tcx>(
15071507
// FIXME(compiler-errors): We may benefit from resolving regions here.
15081508
if ocx.select_where_possible().is_empty()
15091509
&& let item_ty = infcx.resolve_vars_if_possible(item_ty)
1510-
&& let Some(item_ty) = item_ty.make_suggestable(tcx, false)
1510+
&& let Some(item_ty) = item_ty.make_suggestable(tcx, false, None)
15111511
&& let Some(sugg) = formatter(
15121512
tcx,
15131513
infcx.resolve_vars_if_possible(args),

compiler/rustc_hir_analysis/src/collect/type_of.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
4747
let ty = tcx.fold_regions(ty, |r, _| {
4848
if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r }
4949
});
50-
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
50+
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false, None) {
5151
(ty, Some((span, Applicability::MachineApplicable)))
5252
} else {
5353
(ty, None)
@@ -587,7 +587,7 @@ fn infer_placeholder_type<'a>(
587587
suggestions.clear();
588588
}
589589

590-
if let Some(ty) = ty.make_suggestable(tcx, false) {
590+
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
591591
err.span_suggestion(
592592
span,
593593
format!("provide a type for the {kind}"),
@@ -606,7 +606,7 @@ fn infer_placeholder_type<'a>(
606606
let mut diag = bad_placeholder(tcx, vec![span], kind);
607607

608608
if !ty.references_error() {
609-
if let Some(ty) = ty.make_suggestable(tcx, false) {
609+
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
610610
diag.span_suggestion(
611611
span,
612612
"replace with the correct type",

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
809809
return true;
810810
}
811811
&hir::FnRetTy::DefaultReturn(span) if expected.is_unit() => {
812-
if let Some(found) = found.make_suggestable(self.tcx, false) {
812+
if let Some(found) = found.make_suggestable(self.tcx, false, None) {
813813
err.subdiagnostic(
814814
self.dcx(),
815815
errors::AddReturnTypeSuggestion::Add { span, found: found.to_string() },

compiler/rustc_hir_typeck/src/op.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -601,8 +601,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
601601
if let Some(output_def_id) = output_def_id
602602
&& let Some(trait_def_id) = trait_def_id
603603
&& self.tcx.parent(output_def_id) == trait_def_id
604-
&& let Some(output_ty) =
605-
output_ty.make_suggestable(self.tcx, false)
604+
&& let Some(output_ty) = output_ty
605+
.make_suggestable(self.tcx, false, None)
606606
{
607607
Some(("Output", output_ty))
608608
} else {

compiler/rustc_hir_typeck/src/pat.rs

+26-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
1818
use rustc_span::hygiene::DesugaringKind;
1919
use rustc_span::source_map::Spanned;
2020
use rustc_span::symbol::{kw, sym, Ident};
21-
use rustc_span::Span;
22-
use rustc_span::{BytePos, DUMMY_SP};
21+
use rustc_span::{BytePos, Span, DUMMY_SP};
2322
use rustc_target::abi::FieldIdx;
2423
use rustc_trait_selection::traits::{ObligationCause, Pattern};
2524
use ty::VariantDef;
@@ -211,6 +210,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
211210
PatKind::Tuple(elements, ddpos) => {
212211
self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info)
213212
}
213+
PatKind::Box(inner) if self.tcx.features().deref_patterns => {
214+
self.check_pat_deref(pat.span, inner, expected, pat_info)
215+
}
214216
PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info),
215217
PatKind::Ref(inner, mutbl) => self.check_pat_ref(pat, inner, mutbl, expected, pat_info),
216218
PatKind::Slice(before, slice, after) => {
@@ -1975,6 +1977,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
19751977
box_ty
19761978
}
19771979

1980+
fn check_pat_deref(
1981+
&self,
1982+
span: Span,
1983+
inner: &'tcx Pat<'tcx>,
1984+
expected: Ty<'tcx>,
1985+
pat_info: PatInfo<'tcx, '_>,
1986+
) -> Ty<'tcx> {
1987+
let tcx = self.tcx;
1988+
// FIXME(deref_patterns): use `DerefPure` for soundness
1989+
// FIXME(deref_patterns): use `DerefMut` when required
1990+
// <expected as Deref>::Target
1991+
let ty = Ty::new_projection(
1992+
tcx,
1993+
tcx.require_lang_item(hir::LangItem::DerefTarget, Some(span)),
1994+
[expected],
1995+
);
1996+
let ty = self.normalize(span, ty);
1997+
let ty = self.try_structurally_resolve_type(span, ty);
1998+
self.check_pat(inner, ty, pat_info);
1999+
expected
2000+
}
2001+
19782002
// Precondition: Pat is Ref(inner)
19792003
fn check_pat_ref(
19802004
&self,

compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs

+46-31
Original file line numberDiff line numberDiff line change
@@ -546,40 +546,55 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
546546
}
547547
}
548548
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
549-
let mut printer = fmt_printer(self, Namespace::ValueNS);
550-
printer.print_def_path(def_id, args).unwrap();
551-
let def_path = printer.into_buffer();
552-
553-
// We only care about whether we have to add `&` or `&mut ` for now.
554-
// This is the case if the last adjustment is a borrow and the
555-
// first adjustment was not a builtin deref.
556-
let adjustment = match typeck_results.expr_adjustments(receiver) {
557-
[
558-
Adjustment { kind: Adjust::Deref(None), target: _ },
559-
..,
560-
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ },
561-
] => "",
562-
[
563-
..,
564-
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)), target: _ },
565-
] => hir::Mutability::from(*mut_).ref_prefix_str(),
566-
_ => "",
567-
};
549+
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
550+
span: rustc_span::DUMMY_SP,
551+
kind: TypeVariableOriginKind::MiscVariable,
552+
}));
553+
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
554+
let mut printer = fmt_printer(self, Namespace::ValueNS);
555+
printer.print_def_path(def_id, args).unwrap();
556+
let def_path = printer.into_buffer();
557+
558+
// We only care about whether we have to add `&` or `&mut ` for now.
559+
// This is the case if the last adjustment is a borrow and the
560+
// first adjustment was not a builtin deref.
561+
let adjustment = match typeck_results.expr_adjustments(receiver) {
562+
[
563+
Adjustment { kind: Adjust::Deref(None), target: _ },
564+
..,
565+
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ },
566+
] => "",
567+
[
568+
..,
569+
Adjustment {
570+
kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)),
571+
target: _,
572+
},
573+
] => hir::Mutability::from(*mut_).ref_prefix_str(),
574+
_ => "",
575+
};
568576

569-
multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified(
570-
receiver.span,
571-
def_path,
572-
adjustment,
573-
successor,
574-
));
577+
multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified(
578+
receiver.span,
579+
def_path,
580+
adjustment,
581+
successor,
582+
));
583+
}
575584
}
576585
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
577-
let ty_info = ty_to_string(self, ty, None);
578-
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
579-
ty_info,
580-
data,
581-
should_wrap_expr,
582-
));
586+
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
587+
span: rustc_span::DUMMY_SP,
588+
kind: TypeVariableOriginKind::MiscVariable,
589+
}));
590+
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
591+
let ty_info = ty_to_string(self, ty, None);
592+
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
593+
ty_info,
594+
data,
595+
should_wrap_expr,
596+
));
597+
}
583598
}
584599
}
585600
match error_code {

compiler/rustc_middle/src/thir.rs

+9
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,7 @@ impl<'tcx> Pat<'tcx> {
647647
AscribeUserType { subpattern, .. }
648648
| Binding { subpattern: Some(subpattern), .. }
649649
| Deref { subpattern }
650+
| DerefPattern { subpattern }
650651
| InlineConstant { subpattern, .. } => subpattern.walk_(it),
651652
Leaf { subpatterns } | Variant { subpatterns, .. } => {
652653
subpatterns.iter().for_each(|field| field.pattern.walk_(it))
@@ -762,6 +763,11 @@ pub enum PatKind<'tcx> {
762763
subpattern: Box<Pat<'tcx>>,
763764
},
764765

766+
/// Deref pattern, written `box P` for now.
767+
DerefPattern {
768+
subpattern: Box<Pat<'tcx>>,
769+
},
770+
765771
/// One of the following:
766772
/// * `&str` (represented as a valtree), which will be handled as a string pattern and thus
767773
/// exhaustiveness checking will detect if you use the same string twice in different
@@ -1172,6 +1178,9 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
11721178
}
11731179
write!(f, "{subpattern}")
11741180
}
1181+
PatKind::DerefPattern { ref subpattern } => {
1182+
write!(f, "k#deref {subpattern}")
1183+
}
11751184
PatKind::Constant { value } => write!(f, "{value}"),
11761185
PatKind::InlineConstant { def: _, ref subpattern } => {
11771186
write!(f, "{} (from inline const)", subpattern)

compiler/rustc_middle/src/thir/visit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ pub fn walk_pat<'thir, 'tcx: 'thir, V: Visitor<'thir, 'tcx>>(
229229
match &pat.kind {
230230
AscribeUserType { subpattern, ascription: _ }
231231
| Deref { subpattern }
232+
| DerefPattern { subpattern }
232233
| Binding {
233234
subpattern: Some(subpattern),
234235
mutability: _,

0 commit comments

Comments
 (0)