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 5 pull requests #80212

Closed
wants to merge 11 commits into from
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx
ty::Generator(_, substs, _) => {
let sig = substs.as_generator().poly_sig();

let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { kind: ty::BrEnv });
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);

let pin_did = tcx.require_lang_item(rustc_hir::LangItem::Pin, None);
Expand Down
33 changes: 26 additions & 7 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ use TokenTreeOrTokenTreeSlice::*;
use crate::mbe::{self, TokenTree};

use rustc_ast::token::{self, DocComment, Nonterminal, Token};
use rustc_parse::parser::Parser;
use rustc_parse::parser::{OrPatNonterminalMode, Parser};
use rustc_session::parse::ParseSess;
use rustc_span::symbol::MacroRulesNormalizedIdent;
use rustc_span::{edition::Edition, symbol::MacroRulesNormalizedIdent};

use smallvec::{smallvec, SmallVec};

Expand Down Expand Up @@ -414,6 +414,18 @@ fn token_name_eq(t1: &Token, t2: &Token) -> bool {
}
}

/// In edition 2015/18, `:pat` can only match `pat<no_top_alt>` because otherwise, we have
/// breakage. As of edition 2021, `:pat` matches `top_pat`.
///
/// See <https://github.com/rust-lang/rust/issues/54883> for more info.
fn or_pat_mode(edition: Edition) -> OrPatNonterminalMode {
match edition {
Edition::Edition2015 | Edition::Edition2018 => OrPatNonterminalMode::NoTopAlt,
// FIXME(mark-i-m): uncomment this when edition 2021 machinery is added.
// Edition::Edition2021 => OrPatNonterminalMode::TopPat,
}
}

/// Process the matcher positions of `cur_items` until it is empty. In the process, this will
/// produce more items in `next_items`, `eof_items`, and `bb_items`.
///
Expand Down Expand Up @@ -553,10 +565,14 @@ fn inner_parse_loop<'root, 'tt>(

// We need to match a metavar with a valid ident... call out to the black-box
// parser by adding an item to `bb_items`.
TokenTree::MetaVarDecl(_, _, kind) => {
// Built-in nonterminals never start with these tokens,
// so we can eliminate them from consideration.
if Parser::nonterminal_may_begin_with(kind, token) {
TokenTree::MetaVarDecl(span, _, kind) => {
// Built-in nonterminals never start with these tokens, so we can eliminate
// them from consideration.
//
// We use the span of the metavariable declaration to determine any
// edition-specific matching behavior for non-terminals.
if Parser::nonterminal_may_begin_with(kind, token, or_pat_mode(span.edition()))
{
bb_items.push(item);
}
}
Expand Down Expand Up @@ -717,7 +733,10 @@ pub(super) fn parse_tt(parser: &mut Cow<'_, Parser<'_>>, ms: &[TokenTree]) -> Na
let mut item = bb_items.pop().unwrap();
if let TokenTree::MetaVarDecl(span, _, kind) = item.top_elts.get_tt(item.idx) {
let match_cur = item.match_cur;
let nt = match parser.to_mut().parse_nonterminal(kind) {
// We use the span of the metavariable declaration to determine any
// edition-specific matching behavior for non-terminals.
let nt = match parser.to_mut().parse_nonterminal(kind, or_pat_mode(span.edition()))
{
Err(mut err) => {
err.span_label(
span,
Expand Down
3 changes: 2 additions & 1 deletion compiler/rustc_infer/src/infer/canonical/canonicalizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
r: ty::Region<'tcx>,
) -> ty::Region<'tcx> {
let var = self.canonical_var(info, r.into());
let region = ty::ReLateBound(self.binder_index, ty::BoundRegion::BrAnon(var.as_u32()));
let br = ty::BoundRegion { kind: ty::BrAnon(var.as_u32()) };
let region = ty::ReLateBound(self.binder_index, br);
self.tcx().mk_region(region)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/canonical/substitute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ where
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
};

tcx.replace_escaping_bound_vars(value, fld_r, fld_t, fld_c).0
tcx.replace_escaping_bound_vars(value, fld_r, fld_t, fld_c)
}
}
6 changes: 4 additions & 2 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ fn msg_span_from_early_bound_and_free_regions(
}
(format!("the lifetime `{}` as defined on", br.name), sp)
}
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
ty::ReFree(ty::FreeRegion {
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
}) => {
let mut sp = sm.guess_head_span(tcx.hir().span(node));
if let Some(param) =
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
Expand Down Expand Up @@ -2279,7 +2281,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
&self,
var_origin: RegionVariableOrigin,
) -> DiagnosticBuilder<'tcx> {
let br_string = |br: ty::BoundRegion| {
let br_string = |br: ty::BoundRegionKind| {
let mut s = match br {
ty::BrNamed(_, name) => name.to_string(),
_ => String::new(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
pub(super) fn find_anon_type(
&self,
region: Region<'tcx>,
br: &ty::BoundRegion,
br: &ty::BoundRegionKind,
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
fn find_component_for_bound_region(
&self,
arg: &'tcx hir::Ty<'tcx>,
br: &ty::BoundRegion,
br: &ty::BoundRegionKind,
) -> Option<&'tcx hir::Ty<'tcx>> {
let mut nested_visitor = FindNestedTypeVisitor {
tcx: self.tcx(),
Expand All @@ -80,7 +80,7 @@ struct FindNestedTypeVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
// The bound_region corresponding to the Refree(freeregion)
// associated with the anonymous region we are looking for.
bound_region: ty::BoundRegion,
bound_region: ty::BoundRegionKind,
// The type where the anonymous lifetime appears
// for e.g., Vec<`&u8`> and <`&u8`>
found_type: Option<&'tcx hir::Ty<'tcx>>,
Expand Down Expand Up @@ -207,7 +207,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
struct TyPathVisitor<'tcx> {
tcx: TyCtxt<'tcx>,
found_it: bool,
bound_region: ty::BoundRegion,
bound_region: ty::BoundRegionKind,
current_index: ty::DebruijnIndex,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub(super) struct AnonymousParamInfo<'tcx> {
pub param: &'tcx hir::Param<'tcx>,
/// The type corresponding to the anonymous region parameter.
pub param_ty: Ty<'tcx>,
/// The ty::BoundRegion corresponding to the anonymous region.
pub bound_region: ty::BoundRegion,
/// The ty::BoundRegionKind corresponding to the anonymous region.
pub bound_region: ty::BoundRegionKind,
/// The `Span` of the parameter type.
pub param_ty_span: Span,
/// Signals that the argument is the first parameter in the declaration.
Expand Down Expand Up @@ -43,7 +43,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
ty::ReEarlyBound(ebr) => (
self.tcx().parent(ebr.def_id).unwrap(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
};
Expand Down Expand Up @@ -145,7 +145,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
pub(super) fn is_return_type_anon(
&self,
scope_def_id: LocalDefId,
br: ty::BoundRegion,
br: ty::BoundRegionKind,
decl: &hir::FnDecl<'_>,
) -> Option<Span> {
let ret_ty = self.tcx().type_of(scope_def_id);
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_infer/src/infer/higher_ranked/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
// (i.e., if there are no placeholders).
let next_universe = self.universe().next_universe();

let fld_r = |br| {
let fld_r = |br: ty::BoundRegion| {
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
universe: next_universe,
name: br,
name: br.kind,
}))
};

Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_infer/src/infer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ pub enum RegionVariableOrigin {

/// Region variables created for bound regions
/// in a function or method that is called
LateBoundRegion(Span, ty::BoundRegion, LateBoundRegionConversionTime),
LateBoundRegion(Span, ty::BoundRegionKind, LateBoundRegionConversionTime),

UpvarRegion(ty::UpvarId, Span),

Expand Down Expand Up @@ -1421,7 +1421,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
where
T: TypeFoldable<'tcx>,
{
let fld_r = |br| self.next_region_var(LateBoundRegion(span, br, lbrct));
let fld_r =
|br: ty::BoundRegion| self.next_region_var(LateBoundRegion(span, br.kind, lbrct));
let fld_t = |_| {
self.next_ty_var(TypeVariableOrigin {
kind: TypeVariableOriginKind::MiscVariable,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/nll_relate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ where
universe
});

let placeholder = ty::PlaceholderRegion { universe, name: br };
let placeholder = ty::PlaceholderRegion { universe, name: br.kind };
delegate.next_placeholder_region(placeholder)
} else {
delegate.next_existential_region_var(true)
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ich/impls_ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
ty::ReEmpty(universe) => {
universe.hash_stable(hcx, hasher);
}
ty::ReLateBound(db, ty::BrAnon(i)) => {
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrAnon(i) }) => {
db.hash_stable(hcx, hasher);
i.hash_stable(hcx, hasher);
}
ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrNamed(def_id, name) }) => {
db.hash_stable(hcx, hasher);
def_id.hash_stable(hcx, hasher);
name.hash_stable(hcx, hasher);
}
ty::ReLateBound(db, ty::BrEnv) => {
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrEnv }) => {
db.hash_stable(hcx, hasher);
}
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {
Expand Down
7 changes: 4 additions & 3 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ impl<'tcx> CanonicalVarValues<'tcx> {
GenericArgKind::Type(..) => {
tcx.mk_ty(ty::Bound(ty::INNERMOST, ty::BoundVar::from_u32(i).into())).into()
}
GenericArgKind::Lifetime(..) => tcx
.mk_region(ty::ReLateBound(ty::INNERMOST, ty::BoundRegion::BrAnon(i)))
.into(),
GenericArgKind::Lifetime(..) => {
let br = ty::BoundRegion { kind: ty::BrAnon(i) };
tcx.mk_region(ty::ReLateBound(ty::INNERMOST, br)).into()
}
GenericArgKind::Const(ct) => tcx
.mk_const(ty::Const {
ty: ct.ty,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ pub struct FreeRegionInfo {
// `LocalDefId` corresponding to FreeRegion
pub def_id: LocalDefId,
// the bound region corresponding to FreeRegion
pub boundregion: ty::BoundRegion,
pub boundregion: ty::BoundRegionKind,
// checks if bound region is in Impl Item
pub is_impl_item: bool,
}
Expand Down Expand Up @@ -1412,15 +1412,15 @@ impl<'tcx> TyCtxt<'tcx> {
})
}

// Returns the `DefId` and the `BoundRegion` corresponding to the given region.
// Returns the `DefId` and the `BoundRegionKind` corresponding to the given region.
pub fn is_suitable_region(self, region: Region<'tcx>) -> Option<FreeRegionInfo> {
let (suitable_region_binding_scope, bound_region) = match *region {
ty::ReFree(ref free_region) => {
(free_region.scope.expect_local(), free_region.bound_region)
}
ty::ReEarlyBound(ref ebr) => (
self.parent(ebr.def_id).unwrap().expect_local(),
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name),
),
_ => return None, // not a free region
};
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_middle/src/ty/error.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::traits::{ObligationCause, ObligationCauseCode};
use crate::ty::diagnostics::suggest_constraining_type_param;
use crate::ty::{self, BoundRegion, Region, Ty, TyCtxt};
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt};
use rustc_ast as ast;
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
use rustc_errors::{pluralize, DiagnosticBuilder};
Expand Down Expand Up @@ -42,8 +42,8 @@ pub enum TypeError<'tcx> {
ArgCount,

RegionsDoesNotOutlive(Region<'tcx>, Region<'tcx>),
RegionsInsufficientlyPolymorphic(BoundRegion, Region<'tcx>),
RegionsOverlyPolymorphic(BoundRegion, Region<'tcx>),
RegionsInsufficientlyPolymorphic(BoundRegionKind, Region<'tcx>),
RegionsOverlyPolymorphic(BoundRegionKind, Region<'tcx>),
RegionsPlaceholderMismatch,

Sorts(ExpectedFound<Ty<'tcx>>),
Expand Down Expand Up @@ -94,7 +94,7 @@ impl<'tcx> fmt::Display for TypeError<'tcx> {
}
}

let br_string = |br: ty::BoundRegion| match br {
let br_string = |br: ty::BoundRegionKind| match br {
ty::BrNamed(_, name) => format!(" {}", name),
_ => String::new(),
};
Expand Down
Loading