Skip to content

Commit

Permalink
Auto merge of rust-lang#122816 - workingjubilee:rollup-2jipmky, r=wor…
Browse files Browse the repository at this point in the history
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122222 (deref patterns: bare-bones feature gate and typechecking)
 - rust-lang#122456 (CFI: Skip non-passed arguments)
 - rust-lang#122696 (Add bare metal riscv32 target.)
 - rust-lang#122771 (add some comments to hir::ModuleItems)
 - 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)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Mar 21, 2024
2 parents 47dd709 + b3869b6 commit ccb841f
Show file tree
Hide file tree
Showing 71 changed files with 796 additions and 739 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Expand Up @@ -413,7 +413,10 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> {
}
}
PatKind::Box(..) => {
gate!(&self, box_patterns, pattern.span, "box pattern syntax is experimental");
if !self.features.deref_patterns {
// Allow box patterns under `deref_patterns`.
gate!(&self, box_patterns, pattern.span, "box pattern syntax is experimental");
}
}
PatKind::Range(_, Some(_), Spanned { node: RangeEnd::Excluded, .. }) => {
gate!(
Expand Down Expand Up @@ -607,13 +610,16 @@ pub fn check_crate(krate: &ast::Crate, sess: &Session, features: &Features) {
};
}

if !visitor.features.deref_patterns {
// Allow box patterns under `deref_patterns`.
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
}
gate_all_legacy_dont_use!(trait_alias, "trait aliases are experimental");
// Despite being a new feature, `where T: Trait<Assoc(): Sized>`, which is RTN syntax now,
// used to be gated under associated_type_bounds, which are right above, so RTN needs to
// be too.
gate_all_legacy_dont_use!(return_type_notation, "return type notation is experimental");
gate_all_legacy_dont_use!(decl_macro, "`macro` is experimental");
gate_all_legacy_dont_use!(box_patterns, "box pattern syntax is experimental");
gate_all_legacy_dont_use!(
exclusive_range_pattern,
"exclusive range pattern syntax is experimental"
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_builtin_macros/src/lib.rs
Expand Up @@ -49,7 +49,6 @@ mod log_syntax;
mod source_util;
mod test;
mod trace_macros;
mod type_ascribe;
mod util;

pub mod asm;
Expand Down Expand Up @@ -99,7 +98,6 @@ pub fn register_builtin_macros(resolver: &mut dyn ResolverExpand) {
std_panic: edition_panic::expand_panic,
stringify: source_util::expand_stringify,
trace_macros: trace_macros::expand_trace_macros,
type_ascribe: type_ascribe::expand_type_ascribe,
unreachable: edition_panic::expand_unreachable,
// tidy-alphabetical-end
}
Expand Down
35 changes: 0 additions & 35 deletions compiler/rustc_builtin_macros/src/type_ascribe.rs

This file was deleted.

3 changes: 3 additions & 0 deletions compiler/rustc_expand/messages.ftl
Expand Up @@ -33,6 +33,9 @@ expand_duplicate_matcher_binding = duplicate matcher binding
expand_expected_comma_in_list =
expected token: `,`
expand_expected_paren_or_brace =
expected `(` or `{"{"}`, found `{$token}`
expand_explain_doc_comment_inner =
inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_expand/src/errors.rs
Expand Up @@ -448,3 +448,11 @@ pub struct InvalidFragmentSpecifier {
pub fragment: Ident,
pub help: String,
}

#[derive(Diagnostic)]
#[diag(expand_expected_paren_or_brace)]
pub struct ExpectedParenOrBrace<'a> {
#[primary_span]
pub span: Span,
pub token: Cow<'a, str>,
}
8 changes: 5 additions & 3 deletions compiler/rustc_expand/src/mbe/quoted.rs
Expand Up @@ -194,9 +194,11 @@ fn parse_tree<'a>(
}
Delimiter::Parenthesis => {}
_ => {
let tok = pprust::token_kind_to_string(&token::OpenDelim(delim));
let msg = format!("expected `(` or `{{`, found `{tok}`");
sess.dcx().span_err(delim_span.entire(), msg);
let token = pprust::token_kind_to_string(&token::OpenDelim(delim));
sess.dcx().emit_err(errors::ExpectedParenOrBrace {
span: delim_span.entire(),
token,
});
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_feature/src/unstable.rs
Expand Up @@ -436,6 +436,8 @@ declare_features! (
(unstable, deprecated_safe, "1.61.0", Some(94978)),
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
(unstable, deprecated_suggestion, "1.61.0", Some(94785)),
/// Allows deref patterns.
(incomplete, deref_patterns, "CURRENT_RUSTC_VERSION", Some(87121)),
/// Controls errors in trait implementations.
(unstable, do_not_recommend, "1.67.0", Some(51992)),
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/astconv/bounds.rs
Expand Up @@ -565,7 +565,7 @@ fn check_assoc_const_binding_type<'tcx>(
let mut guar = ty.visit_with(&mut collector).break_value();

let ty_note = ty
.make_suggestable(tcx, false)
.make_suggestable(tcx, false, None)
.map(|ty| crate::errors::TyOfAssocConstBindingNote { assoc_const, ty });

let enclosing_item_owner_id = tcx
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect.rs
Expand Up @@ -1371,7 +1371,7 @@ fn infer_return_ty_for_fn_sig<'tcx>(
// recursive function definition to leak out into the fn sig.
let mut should_recover = false;

if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false) {
if let Some(ret_ty) = ret_ty.make_suggestable(tcx, false, None) {
diag.span_suggestion(
ty.span,
"replace with the correct return type",
Expand Down Expand Up @@ -1449,7 +1449,7 @@ fn suggest_impl_trait<'tcx>(
let ty::Tuple(types) = *args_tuple.kind() else {
return None;
};
let types = types.make_suggestable(tcx, false)?;
let types = types.make_suggestable(tcx, false, None)?;
let maybe_ret =
if item_ty.is_unit() { String::new() } else { format!(" -> {item_ty}") };
Some(format!(
Expand Down Expand Up @@ -1507,7 +1507,7 @@ fn suggest_impl_trait<'tcx>(
// FIXME(compiler-errors): We may benefit from resolving regions here.
if ocx.select_where_possible().is_empty()
&& let item_ty = infcx.resolve_vars_if_possible(item_ty)
&& let Some(item_ty) = item_ty.make_suggestable(tcx, false)
&& let Some(item_ty) = item_ty.make_suggestable(tcx, false, None)
&& let Some(sugg) = formatter(
tcx,
infcx.resolve_vars_if_possible(args),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Expand Up @@ -47,7 +47,7 @@ fn anon_const_type_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> Ty<'tcx> {
let ty = tcx.fold_regions(ty, |r, _| {
if r.is_erased() { ty::Region::new_error_misc(tcx) } else { r }
});
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false) {
let (ty, opt_sugg) = if let Some(ty) = ty.make_suggestable(tcx, false, None) {
(ty, Some((span, Applicability::MachineApplicable)))
} else {
(ty, None)
Expand Down Expand Up @@ -587,7 +587,7 @@ fn infer_placeholder_type<'a>(
suggestions.clear();
}

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

if !ty.references_error() {
if let Some(ty) = ty.make_suggestable(tcx, false) {
if let Some(ty) = ty.make_suggestable(tcx, false, None) {
diag.span_suggestion(
span,
"replace with the correct type",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Expand Up @@ -809,7 +809,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
return true;
}
&hir::FnRetTy::DefaultReturn(span) if expected.is_unit() => {
if let Some(found) = found.make_suggestable(self.tcx, false) {
if let Some(found) = found.make_suggestable(self.tcx, false, None) {
err.subdiagnostic(
self.dcx(),
errors::AddReturnTypeSuggestion::Add { span, found: found.to_string() },
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_typeck/src/op.rs
Expand Up @@ -601,8 +601,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if let Some(output_def_id) = output_def_id
&& let Some(trait_def_id) = trait_def_id
&& self.tcx.parent(output_def_id) == trait_def_id
&& let Some(output_ty) =
output_ty.make_suggestable(self.tcx, false)
&& let Some(output_ty) = output_ty
.make_suggestable(self.tcx, false, None)
{
Some(("Output", output_ty))
} else {
Expand Down
28 changes: 26 additions & 2 deletions compiler/rustc_hir_typeck/src/pat.rs
Expand Up @@ -18,8 +18,7 @@ use rustc_span::edit_distance::find_best_match_for_name;
use rustc_span::hygiene::DesugaringKind;
use rustc_span::source_map::Spanned;
use rustc_span::symbol::{kw, sym, Ident};
use rustc_span::Span;
use rustc_span::{BytePos, DUMMY_SP};
use rustc_span::{BytePos, Span, DUMMY_SP};
use rustc_target::abi::FieldIdx;
use rustc_trait_selection::traits::{ObligationCause, Pattern};
use ty::VariantDef;
Expand Down Expand Up @@ -211,6 +210,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
PatKind::Tuple(elements, ddpos) => {
self.check_pat_tuple(pat.span, elements, ddpos, expected, pat_info)
}
PatKind::Box(inner) if self.tcx.features().deref_patterns => {
self.check_pat_deref(pat.span, inner, expected, pat_info)
}
PatKind::Box(inner) => self.check_pat_box(pat.span, inner, expected, pat_info),
PatKind::Ref(inner, mutbl) => self.check_pat_ref(pat, inner, mutbl, expected, pat_info),
PatKind::Slice(before, slice, after) => {
Expand Down Expand Up @@ -1975,6 +1977,28 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
box_ty
}

fn check_pat_deref(
&self,
span: Span,
inner: &'tcx Pat<'tcx>,
expected: Ty<'tcx>,
pat_info: PatInfo<'tcx, '_>,
) -> Ty<'tcx> {
let tcx = self.tcx;
// FIXME(deref_patterns): use `DerefPure` for soundness
// FIXME(deref_patterns): use `DerefMut` when required
// <expected as Deref>::Target
let ty = Ty::new_projection(
tcx,
tcx.require_lang_item(hir::LangItem::DerefTarget, Some(span)),
[expected],
);
let ty = self.normalize(span, ty);
let ty = self.try_structurally_resolve_type(span, ty);
self.check_pat(inner, ty, pat_info);
expected
}

// Precondition: Pat is Ref(inner)
fn check_pat_ref(
&self,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_incremental/src/persist/dirty_clean.rs
Expand Up @@ -148,7 +148,7 @@ pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {

let crate_items = tcx.hir_crate_items(());

for id in crate_items.items() {
for id in crate_items.free_items() {
dirty_clean_visitor.check_item(id.owner_id.def_id);
}

Expand Down
77 changes: 46 additions & 31 deletions compiler/rustc_infer/src/infer/error_reporting/need_type_info.rs
Expand Up @@ -546,40 +546,55 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
}
}
InferSourceKind::FullyQualifiedMethodCall { receiver, successor, args, def_id } => {
let mut printer = fmt_printer(self, Namespace::ValueNS);
printer.print_def_path(def_id, args).unwrap();
let def_path = printer.into_buffer();

// We only care about whether we have to add `&` or `&mut ` for now.
// This is the case if the last adjustment is a borrow and the
// first adjustment was not a builtin deref.
let adjustment = match typeck_results.expr_adjustments(receiver) {
[
Adjustment { kind: Adjust::Deref(None), target: _ },
..,
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ },
] => "",
[
..,
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)), target: _ },
] => hir::Mutability::from(*mut_).ref_prefix_str(),
_ => "",
};
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
span: rustc_span::DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
}));
if let Some(args) = args.make_suggestable(self.infcx.tcx, true, placeholder) {
let mut printer = fmt_printer(self, Namespace::ValueNS);
printer.print_def_path(def_id, args).unwrap();
let def_path = printer.into_buffer();

// We only care about whether we have to add `&` or `&mut ` for now.
// This is the case if the last adjustment is a borrow and the
// first adjustment was not a builtin deref.
let adjustment = match typeck_results.expr_adjustments(receiver) {
[
Adjustment { kind: Adjust::Deref(None), target: _ },
..,
Adjustment { kind: Adjust::Borrow(AutoBorrow::Ref(..)), target: _ },
] => "",
[
..,
Adjustment {
kind: Adjust::Borrow(AutoBorrow::Ref(_, mut_)),
target: _,
},
] => hir::Mutability::from(*mut_).ref_prefix_str(),
_ => "",
};

multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified(
receiver.span,
def_path,
adjustment,
successor,
));
multi_suggestions.push(SourceKindMultiSuggestion::new_fully_qualified(
receiver.span,
def_path,
adjustment,
successor,
));
}
}
InferSourceKind::ClosureReturn { ty, data, should_wrap_expr } => {
let ty_info = ty_to_string(self, ty, None);
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
ty_info,
data,
should_wrap_expr,
));
let placeholder = Some(self.next_ty_var(TypeVariableOrigin {
span: rustc_span::DUMMY_SP,
kind: TypeVariableOriginKind::MiscVariable,
}));
if let Some(ty) = ty.make_suggestable(self.infcx.tcx, true, placeholder) {
let ty_info = ty_to_string(self, ty, None);
multi_suggestions.push(SourceKindMultiSuggestion::new_closure_return(
ty_info,
data,
should_wrap_expr,
));
}
}
}
match error_code {
Expand Down

0 comments on commit ccb841f

Please sign in to comment.