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 10 pull requests #80178

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c2de8fe
Stabilize or_insert_with_key
ChaiTRex Oct 18, 2020
75eb72c
passes: prohibit attrs on generic params
davidtwco Nov 15, 2020
866ef87
Update rustc version that or_insert_with_key landed
ChaiTRex Dec 1, 2020
f1b930d
Improved documentation for HashMap/BTreeMap Entry's .or_insert_with_k…
ChaiTRex Dec 8, 2020
f115be9
Removed spurious linebreak from new documentation
ChaiTRex Dec 8, 2020
8fb553c
Add `&mut` as an alias for 'reference' primitive
jyn514 Dec 16, 2020
30c9307
docs: Edit rustc_ast::token::Token
pierwill Dec 17, 2020
dea1363
Suppress `CONST_ITEM_MUTATION` lint if a dereference occurs anywhere
Aaron1011 Dec 17, 2020
56530a2
Fix typo
hkmatsumoto Dec 18, 2020
48d5874
Add the "promise" aliases to the `async` lang feature
yoshuawuyts Nov 19, 2020
fd4ae3a
implement edition-specific :pat behavior for 2015/18
mark-i-m Nov 11, 2020
35f16c6
Switch compiler/ to intra-doc links
jyn514 Dec 1, 2020
328fcee
Make BoundRegion have a kind of BoungRegionKind
jackh726 Dec 18, 2020
ce90308
Rollup merge of #78083 - ChaiTRex:master, r=m-ou-se
Dylan-DPC Dec 19, 2020
caaa6db
Rollup merge of #79073 - davidtwco:issue-78957-const-param-attrs, r=lcnr
Dylan-DPC Dec 19, 2020
5f5b3bc
Rollup merge of #79211 - yoshuawuyts:future-doc-alias, r=Mark-Simulacrum
Dylan-DPC Dec 19, 2020
415a974
Rollup merge of #79612 - jyn514:compiler-links, r=Aaron1011
Dylan-DPC Dec 19, 2020
5ba1b8f
Rollup merge of #80068 - jyn514:mut-reference, r=m-ou-se
Dylan-DPC Dec 19, 2020
825658b
Rollup merge of #80100 - mark-i-m:pattORns-2, r=petrochenkov
Dylan-DPC Dec 19, 2020
79ff5d7
Rollup merge of #80129 - pierwill:patch-6, r=estebank
Dylan-DPC Dec 19, 2020
66042fc
Rollup merge of #80133 - Aaron1011:fix/const-mut-deref, r=estebank
Dylan-DPC Dec 19, 2020
93a0f0a
Rollup merge of #80155 - matsujika:matsujika-patch-1, r=jonas-schievink
Dylan-DPC Dec 19, 2020
8890048
Rollup merge of #80163 - jackh726:binder-refactor-part-3, r=lcnr
Dylan-DPC Dec 19, 2020
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
2 changes: 1 addition & 1 deletion compiler/rustc_ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl Token {
|| self == &OpenDelim(Paren)
}

/// Returns `true` if the token is any literal
/// Returns `true` if the token is any literal.
pub fn is_lit(&self) -> bool {
match self.kind {
Literal(..) => true,
Expand Down
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
2 changes: 0 additions & 2 deletions compiler/rustc_data_structures/src/graph/iterate/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,6 @@ struct Event<N> {
/// those successors), we will pop off that node's `Settled` event.
///
/// [CLR]: https://en.wikipedia.org/wiki/Introduction_to_Algorithms
/// [`NodeStatus`]: ./enum.NodeStatus.html
/// [`TriColorVisitor::node_examined`]: ./trait.TriColorVisitor.html#method.node_examined
pub struct TriColorDepthFirstSearch<'graph, G>
where
G: ?Sized + DirectedGraph + WithNumNodes + WithSuccessors,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_data_structures/src/sorted_map/index_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ use rustc_index::vec::{Idx, IndexVec};
/// to insert into the middle of the sorted array. Users should avoid mutating this data structure
/// in-place.
///
/// [`IndexVec`]: ../../rustc_index/vec/struct.IndexVec.html
/// [`SortedMap`]: ../sorted_map/struct.SortedMap.html
/// [`SortedMap`]: super::SortedMap
#[derive(Clone, Debug)]
pub struct SortedIndexMultiMap<I: Idx, K, V> {
/// The elements of the map in insertion order.
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_data_structures/src/sso/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const SSO_ARRAY_SIZE: usize = 8;
// into_keys/into_values (unstable)
// all raw_entry-related
// PartialEq/Eq (requires sorting the array)
// Entry::or_insert_with_key (unstable)
// Entry::or_insert_with_key
// Vacant/Occupied entries and related
//
// FIXME: In HashMap most methods accepting key reference
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_errors/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ impl Diagnostic {
///
/// This span is *not* considered a ["primary span"][`MultiSpan`]; only
/// the `Span` supplied when creating the diagnostic is primary.
///
/// [`MultiSpan`]: ../rustc_span/struct.MultiSpan.html
pub fn span_label<T: Into<String>>(&mut self, span: Span, label: T) -> &mut Self {
self.span.push_span_label(span, label.into());
self
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
23 changes: 23 additions & 0 deletions compiler/rustc_hir/src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ use crate::{Item, ItemKind, TraitItem, TraitItemKind};

use std::fmt::{self, Display};

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum GenericParamKind {
Type,
Lifetime,
Const,
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum MethodKind {
Trait { body: bool },
Expand Down Expand Up @@ -43,6 +50,7 @@ pub enum Target {
ForeignFn,
ForeignStatic,
ForeignTy,
GenericParam(GenericParamKind),
}

impl Display for Target {
Expand Down Expand Up @@ -77,6 +85,11 @@ impl Display for Target {
Target::ForeignFn => "foreign function",
Target::ForeignStatic => "foreign static item",
Target::ForeignTy => "foreign type",
Target::GenericParam(kind) => match kind {
GenericParamKind::Type => "type parameter",
GenericParamKind::Lifetime => "lifetime parameter",
GenericParamKind::Const => "const parameter",
},
}
)
}
Expand Down Expand Up @@ -124,4 +137,14 @@ impl Target {
hir::ForeignItemKind::Type => Target::ForeignTy,
}
}

pub fn from_generic_param(generic_param: &hir::GenericParam<'_>) -> Target {
match generic_param.kind {
hir::GenericParamKind::Type { .. } => Target::GenericParam(GenericParamKind::Type),
hir::GenericParamKind::Lifetime { .. } => {
Target::GenericParam(GenericParamKind::Lifetime)
}
hir::GenericParamKind::Const { .. } => Target::GenericParam(GenericParamKind::Const),
}
}
}
1 change: 0 additions & 1 deletion compiler/rustc_index/src/bit_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub const WORD_BITS: usize = WORD_BYTES * 8;
/// to or greater than the domain size. All operations that involve two bitsets
/// will panic if the bitsets have differing domain sizes.
///
/// [`GrowableBitSet`]: struct.GrowableBitSet.html
#[derive(Eq, PartialEq, Decodable, Encodable)]
pub struct BitSet<T> {
domain_size: usize,
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
2 changes: 1 addition & 1 deletion compiler/rustc_lexer/src/unescape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn scan_escape(first_char: char, chars: &mut Chars<'_>, mode: Mode) -> Result<ch
return Err(EscapeError::NoBraceInUnicodeEscape);
}

// First characrer must be a hexadecimal digit.
// First character must be a hexadecimal digit.
let mut n_digits = 1;
let mut value: u32 = match chars.next().ok_or(EscapeError::UnclosedUnicodeEscape)? {
'_' => return Err(EscapeError::LeadingUnderscoreUnicodeEscape),
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 @@ -889,7 +889,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 @@ -1411,15 +1411,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
Loading