Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #122818

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
67f1c53
Don't ICE when encountering bound regions in generator interior type
compiler-errors Mar 14, 2024
bca708b
Do binder folding eagerly in bound_coroutine_hidden_types
compiler-errors Mar 14, 2024
e0980cc
add some comments to hir::ModuleItems
RalfJung Mar 20, 2024
3e8ff90
make "expected paren or brace" error translatable
tshepang Mar 20, 2024
2fca27c
Add bare metal riscv32 target.
royb3 Mar 18, 2024
120d357
Add barest-bones deref patterns
Nadrieril Mar 8, 2024
a400dac
Inherit `RUSTC_BOOTSTRAP` when testing wasm
alexcrichton Mar 20, 2024
ff504a0
Improve emit stable mir body
celinval Mar 20, 2024
5f62574
Enable users to dump the body of an instance
celinval Mar 20, 2024
5fae665
Replace closures with `_` when suggesting fully qualified path for me…
estebank Mar 20, 2024
ebacf7a
s/place_debug/place_pretty in SMIR
celinval Mar 21, 2024
a015b90
Make type_ascribe! not a built-in
compiler-errors Mar 21, 2024
1933969
rename items -> free_items
RalfJung Mar 20, 2024
1eeeaa4
Rollup merge of #122222 - Nadrieril:deref-pat-feature-gate, r=compile…
matthiaskrgr Mar 21, 2024
97fa0db
Rollup merge of #122358 - compiler-errors:bound-regions-in-generator,…
matthiaskrgr Mar 21, 2024
2fb1fe2
Rollup merge of #122696 - royb3:riscv32ima, r=petrochenkov
matthiaskrgr Mar 21, 2024
342b2bf
Rollup merge of #122771 - RalfJung:module-items, r=oli-obk
matthiaskrgr Mar 21, 2024
01c5e74
Rollup merge of #122773 - tshepang:make-expand-translatable, r=fee1-dead
matthiaskrgr Mar 21, 2024
e94cd88
Rollup merge of #122795 - alexcrichton:fix-wasm-beta-bootstrap, r=Mar…
matthiaskrgr Mar 21, 2024
b1d347b
Rollup merge of #122799 - estebank:issue-122569, r=fee1-dead
matthiaskrgr Mar 21, 2024
edb0a1b
Rollup merge of #122801 - celinval:smir-pretty, r=compiler-errors
matthiaskrgr Mar 21, 2024
6d186e3
Rollup merge of #122806 - compiler-errors:type-ascribe, r=fmease
matthiaskrgr Mar 21, 2024
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
10 changes: 8 additions & 2 deletions compiler/rustc_ast_passes/src/feature_gate.rs
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading
Loading