Skip to content
Closed
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
9 changes: 7 additions & 2 deletions compiler/rustc_ast/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3901,12 +3901,17 @@ pub struct Delegation {
pub from_glob: bool,
}

#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
pub enum DelegationSuffixes {
List(ThinVec<(Ident, Option<Ident>)>),
Glob(Span),
}

#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
pub struct DelegationMac {
pub qself: Option<Box<QSelf>>,
pub prefix: Path,
// Some for list delegation, and None for glob delegation.
pub suffixes: Option<ThinVec<(Ident, Option<Ident>)>>,
pub suffixes: DelegationSuffixes,
pub body: Option<Box<Block>>,
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ macro_rules! common_visitor_and_walkers {
Defaultness,
Delegation,
DelegationMac,
DelegationSuffixes,
DelimArgs,
DelimSpan,
EnumDef,
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_ast_pretty/src/pprust/state/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,10 @@ impl<'a> State<'a> {
&item.vis,
&deleg.qself,
&deleg.prefix,
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
match &deleg.suffixes {
ast::DelegationSuffixes::List(s) => DelegationKind::List(s),
ast::DelegationSuffixes::Glob(_) => DelegationKind::Glob,
},
&deleg.body,
),
}
Expand Down Expand Up @@ -651,7 +654,10 @@ impl<'a> State<'a> {
vis,
&deleg.qself,
&deleg.prefix,
deleg.suffixes.as_ref().map_or(DelegationKind::Glob, |s| DelegationKind::List(s)),
match &deleg.suffixes {
ast::DelegationSuffixes::List(s) => DelegationKind::List(s),
ast::DelegationSuffixes::Glob(_) => DelegationKind::Glob,
},
&deleg.body,
),
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_borrowck/src/type_check/input_output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
return;
}

// If the MIR body was constructed via `construct_error` (because an
// earlier pass like match checking failed), its args may not match
// the user-provided signature (e.g. a coroutine with too many
// parameters). Bail out as this can cause panic,
// see <https://github.com/rust-lang/rust/issues/139570>.
if self.body.tainted_by_errors.is_some() {
return;
}

let user_provided_poly_sig = self.tcx().closure_user_provided_sig(mir_def_id);

// Instantiate the canonicalized variables from user-provided signature
Expand Down
11 changes: 9 additions & 2 deletions compiler/rustc_expand/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,26 +1019,32 @@ impl SyntaxExtension {
pub fn glob_delegation(
trait_def_id: DefId,
impl_def_id: LocalDefId,
star_span: Span,
edition: Edition,
) -> SyntaxExtension {
struct GlobDelegationExpanderImpl {
trait_def_id: DefId,
impl_def_id: LocalDefId,
star_span: Span,
}
impl GlobDelegationExpander for GlobDelegationExpanderImpl {
fn expand(
&self,
ecx: &mut ExtCtxt<'_>,
) -> ExpandResult<Vec<(Ident, Option<Ident>)>, ()> {
match ecx.resolver.glob_delegation_suffixes(self.trait_def_id, self.impl_def_id) {
match ecx.resolver.glob_delegation_suffixes(
self.trait_def_id,
self.impl_def_id,
self.star_span,
) {
Ok(suffixes) => ExpandResult::Ready(suffixes),
Err(Indeterminate) if ecx.force_mode => ExpandResult::Ready(Vec::new()),
Err(Indeterminate) => ExpandResult::Retry(()),
}
}
}

let expander = GlobDelegationExpanderImpl { trait_def_id, impl_def_id };
let expander = GlobDelegationExpanderImpl { trait_def_id, impl_def_id, star_span };
SyntaxExtension::default(SyntaxExtensionKind::GlobDelegation(Arc::new(expander)), edition)
}

Expand Down Expand Up @@ -1170,6 +1176,7 @@ pub trait ResolverExpand {
&self,
trait_def_id: DefId,
impl_def_id: LocalDefId,
star_span: Span,
) -> Result<Vec<(Ident, Option<Ident>)>, Indeterminate>;

/// Record the name of an opaque `Ty::ImplTrait` pre-expansion so that it can be used
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list};
use rustc_ast::{
self as ast, AssocItemKind, AstNodeWrapper, AttrArgs, AttrItemKind, AttrStyle, AttrVec,
DUMMY_NODE_ID, EarlyParsedAttribute, ExprKind, ForeignItemKind, HasAttrs, HasNodeId, Inline,
ItemKind, MacStmtStyle, MetaItemInner, MetaItemKind, ModKind, NodeId, PatKind, StmtKind,
TyKind, token,
DUMMY_NODE_ID, DelegationSuffixes, EarlyParsedAttribute, ExprKind, ForeignItemKind, HasAttrs,
HasNodeId, Inline, ItemKind, MacStmtStyle, MetaItemInner, MetaItemKind, ModKind, NodeId,
PatKind, StmtKind, TyKind, token,
};
use rustc_ast_pretty::pprust;
use rustc_attr_parsing::parser::AllowExprMetavar;
Expand Down Expand Up @@ -2401,7 +2401,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
res
}
None if let Some((deleg, item)) = node.delegation() => {
let Some(suffixes) = &deleg.suffixes else {
let DelegationSuffixes::List(suffixes) = &deleg.suffixes else {
let traitless_qself =
matches!(&deleg.qself, Some(qself) if qself.position == 0);
let (item, of_trait) = match node.to_annotatable() {
Expand Down
13 changes: 10 additions & 3 deletions compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// being stalled on a coroutine.
self.select_obligations_where_possible(|_| {});

let ty::TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
else {
bug!();
let defining_opaque_types_and_generators = match self.typing_mode() {
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
defining_opaque_types_and_generators
}
ty::TypingMode::Coherence
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::PostAnalysis => {
bug!()
}
};

if defining_opaque_types_and_generators
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_hir_typeck/src/opaque_types.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use rustc_hir::def::DefKind;
use rustc_infer::traits::ObligationCause;
use rustc_middle::bug;
use rustc_middle::ty::{
self, DefiningScopeKind, DefinitionSiteHiddenType, OpaqueTypeKey, ProvisionalHiddenType,
TypeVisitableExt, TypingMode,
TypeVisitableExt,
};
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
use rustc_trait_selection::opaque_types::{
Expand Down Expand Up @@ -97,9 +98,16 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
debug!(?opaque_types);

let tcx = self.tcx;
let TypingMode::Analysis { defining_opaque_types_and_generators } = self.typing_mode()
else {
unreachable!();
let defining_opaque_types_and_generators = match self.typing_mode() {
ty::TypingMode::Analysis { defining_opaque_types_and_generators } => {
defining_opaque_types_and_generators
}
ty::TypingMode::Coherence
| ty::TypingMode::Borrowck { .. }
| ty::TypingMode::PostBorrowckAnalysis { .. }
| ty::TypingMode::PostAnalysis => {
bug!()
}
};

for def_id in defining_opaque_types_and_generators {
Expand Down
26 changes: 24 additions & 2 deletions compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,15 +783,37 @@ impl<'tcx> LateLintPass<'tcx> for RustcMustMatchExhaustively {
}
}
}
hir::ExprKind::If(expr, ..) if let ExprKind::Let(expr) = expr.kind => {
hir::ExprKind::Let(expr, ..) => {
if let Some(attr_span) = is_rustc_must_match_exhaustively(cx, expr.init.hir_id) {
cx.emit_span_lint(
RUSTC_MUST_MATCH_EXHAUSTIVELY,
expr.span,
RustcMustMatchExhaustivelyNotExhaustive {
attr_span,
pat_span: expr.span,
message: "using if let only matches on one variant (try using `match`)",
message: "using `if let` only matches on one variant (try using `match`)",
},
);
}
}
_ => {}
}
}

fn check_stmt(&mut self, cx: &LateContext<'tcx>, stmt: &'tcx rustc_hir::Stmt<'tcx>) {
match stmt.kind {
rustc_hir::StmtKind::Let(let_stmt) => {
if let_stmt.els.is_some()
&& let Some(attr_span) =
is_rustc_must_match_exhaustively(cx, let_stmt.pat.hir_id)
{
cx.emit_span_lint(
RUSTC_MUST_MATCH_EXHAUSTIVELY,
let_stmt.span,
RustcMustMatchExhaustivelyNotExhaustive {
attr_span,
pat_span: let_stmt.pat.span,
message: "using `let else` only matches on one variant (try using `match`)",
},
);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ where
// normalizing the self type as well, since type variables are not uniquified.
let goal = self.resolve_vars_if_possible(goal);

if let TypingMode::Coherence = self.typing_mode()
if self.typing_mode().is_coherence()
&& let Ok(candidate) = self.consider_coherence_unknowable_candidate(goal)
{
candidates.push(candidate);
Expand Down
13 changes: 9 additions & 4 deletions compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -857,7 +857,7 @@ impl<'a> Parser<'a> {
kind: AssocItemKind::DelegationMac(Box::new(DelegationMac {
qself: None,
prefix: of_trait.trait_ref.path.clone(),
suffixes: None,
suffixes: DelegationSuffixes::Glob(whole_reuse_span),
body,
})),
}));
Expand All @@ -879,10 +879,12 @@ impl<'a> Parser<'a> {

Ok(if self.eat_path_sep() {
let suffixes = if self.eat(exp!(Star)) {
None
DelegationSuffixes::Glob(self.prev_token.span)
} else {
let parse_suffix = |p: &mut Self| Ok((p.parse_path_segment_ident()?, rename(p)?));
Some(self.parse_delim_comma_seq(exp!(OpenBrace), exp!(CloseBrace), parse_suffix)?.0)
DelegationSuffixes::List(
self.parse_delim_comma_seq(exp!(OpenBrace), exp!(CloseBrace), parse_suffix)?.0,
)
};

ItemKind::DelegationMac(Box::new(DelegationMac {
Expand Down Expand Up @@ -1519,7 +1521,10 @@ impl<'a> Parser<'a> {
let span = self.psess.source_map().guess_head_span(span);
let descr = kind.descr();
let help = match kind {
ItemKind::DelegationMac(deleg) if deleg.suffixes.is_none() => false,
ItemKind::DelegationMac(box DelegationMac {
suffixes: DelegationSuffixes::Glob(_),
..
}) => false,
_ => true,
};
self.dcx().emit_err(errors::BadItemKind { span, descr, ctx, help });
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3872,8 +3872,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> {

let Some(body) = &delegation.body else { return };
self.with_rib(ValueNS, RibKind::FnOrCoroutine, |this| {
let span = delegation.path.segments.last().unwrap().ident.span;
let ident = Ident::new(kw::SelfLower, span.normalize_to_macro_rules());
let ident = Ident::new(kw::SelfLower, body.span.normalize_to_macro_rules());
let res = Res::Local(delegation.id);
this.innermost_rib_bindings(ValueNS).insert(ident, res);

Expand Down
23 changes: 15 additions & 8 deletions compiler/rustc_resolve/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use std::mem;
use std::sync::Arc;

use rustc_ast::{self as ast, Crate, DUMMY_NODE_ID, NodeId};
use rustc_ast::{self as ast, Crate, DUMMY_NODE_ID, DelegationSuffixes, NodeId};
use rustc_ast_pretty::pprust;
use rustc_attr_parsing::AttributeParser;
use rustc_errors::{Applicability, DiagCtxtHandle, StashKey};
Expand Down Expand Up @@ -286,7 +286,8 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
InvocationKind::Derive { ref path, .. } => (path, MacroKind::Derive),
InvocationKind::GlobDelegation { ref item, .. } => {
let ast::AssocItemKind::DelegationMac(deleg) = &item.kind else { unreachable!() };
deleg_impl = Some(self.invocation_parent(invoc_id));
let DelegationSuffixes::Glob(star_span) = deleg.suffixes else { unreachable!() };
deleg_impl = Some((self.invocation_parent(invoc_id), star_span));
// It is sufficient to consider glob delegation a bang macro for now.
(&deleg.prefix, MacroKind::Bang)
}
Expand Down Expand Up @@ -530,6 +531,7 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {
&self,
trait_def_id: DefId,
impl_def_id: LocalDefId,
star_span: Span,
) -> Result<Vec<(Ident, Option<Ident>)>, Indeterminate> {
let target_trait = self.expect_module(trait_def_id);
if !target_trait.unexpanded_invocations.borrow().is_empty() {
Expand All @@ -549,13 +551,13 @@ impl<'ra, 'tcx> ResolverExpand for Resolver<'ra, 'tcx> {

let mut idents = Vec::new();
target_trait.for_each_child(self, |this, ident, orig_ident_span, ns, _binding| {
// FIXME: Adjust hygiene for idents from globs, like for glob imports.
if let Some(overriding_keys) = this.impl_binding_keys.get(&impl_def_id)
&& overriding_keys.contains(&BindingKey::new(ident, ns))
{
// The name is overridden, do not produce it from the glob delegation.
} else {
idents.push((ident.orig(orig_ident_span), None));
// FIXME: Adjust hygiene for idents from globs, like for glob imports.
idents.push((ident.orig(star_span.with_ctxt(orig_ident_span.ctxt())), None));
}
});
Ok(idents)
Expand All @@ -579,7 +581,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
parent_scope: &ParentScope<'ra>,
node_id: NodeId,
force: bool,
deleg_impl: Option<LocalDefId>,
deleg_impl: Option<(LocalDefId, Span)>,
invoc_in_mod_inert_attr: Option<LocalDefId>,
suggestion_span: Option<Span>,
) -> Result<(Arc<SyntaxExtension>, Res), Indeterminate> {
Expand Down Expand Up @@ -792,7 +794,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
kind: MacroKind,
parent_scope: &ParentScope<'ra>,
force: bool,
deleg_impl: Option<LocalDefId>,
deleg_impl: Option<(LocalDefId, Span)>,
invoc_in_mod_inert_attr: Option<(LocalDefId, NodeId)>,
ignore_import: Option<Import<'ra>>,
suggestion_span: Option<Span>,
Expand Down Expand Up @@ -877,10 +879,15 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {

let res = res?;
let ext = match deleg_impl {
Some(impl_def_id) => match res {
Some((impl_def_id, star_span)) => match res {
def::Res::Def(DefKind::Trait, def_id) => {
let edition = self.tcx.sess.edition();
Some(Arc::new(SyntaxExtension::glob_delegation(def_id, impl_def_id, edition)))
Some(Arc::new(SyntaxExtension::glob_delegation(
def_id,
impl_def_id,
star_span,
edition,
)))
}
_ => None,
},
Expand Down
4 changes: 0 additions & 4 deletions tests/crashes/139570.rs

This file was deleted.

1 change: 1 addition & 0 deletions tests/run-make/duplicate-profiler-builtins/rmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// together without getting an error about duplicate profiler_builtins.

//@ needs-profiler-runtime
//@ needs-dynamic-linking

use run_make_support::{dynamic_lib_name, rustc};

Expand Down
3 changes: 3 additions & 0 deletions tests/ui-fulldeps/internal-lints/must_match_exhaustively.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ fn foo(f: Foo) {

if let Foo::A { .. } = f {}
//~^ ERROR match is not exhaustive

let Foo::A { .. } = f else { loop {} };
//~^ ERROR match is not exhaustive
}

fn main() {}
Loading
Loading