Auto merge of #111174 - matthiaskrgr:rollup-ncnqivh, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #110859 (Explicitly reject negative and reservation drop impls) - #111020 (Validate resolution for SelfCtor too.) - #111024 (Use the full Fingerprint when stringifying Svh) - #111027 (Remove `allow(rustc::potential_query_instability)` for `builtin_macros`) - #111039 (Encode def span for foreign return-position `impl Trait` in trait) - #111070 (Don't suffix `RibKind` variants) - #111094 (Add needs-unwind annotations to tests that need stack unwinding) - #111103 (correctly recurse when expanding anon consts) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
eac35583d2
43 changed files with 324 additions and 180 deletions
|
@ -3165,6 +3165,7 @@ dependencies = [
|
||||||
"rustc_expand",
|
"rustc_expand",
|
||||||
"rustc_feature",
|
"rustc_feature",
|
||||||
"rustc_fluent_macro",
|
"rustc_fluent_macro",
|
||||||
|
"rustc_index",
|
||||||
"rustc_lexer",
|
"rustc_lexer",
|
||||||
"rustc_lint_defs",
|
"rustc_lint_defs",
|
||||||
"rustc_macros",
|
"rustc_macros",
|
||||||
|
|
|
@ -14,6 +14,7 @@ rustc_data_structures = { path = "../rustc_data_structures" }
|
||||||
rustc_errors = { path = "../rustc_errors" }
|
rustc_errors = { path = "../rustc_errors" }
|
||||||
rustc_expand = { path = "../rustc_expand" }
|
rustc_expand = { path = "../rustc_expand" }
|
||||||
rustc_feature = { path = "../rustc_feature" }
|
rustc_feature = { path = "../rustc_feature" }
|
||||||
|
rustc_index = { path = "../rustc_index" }
|
||||||
rustc_lexer = { path = "../rustc_lexer" }
|
rustc_lexer = { path = "../rustc_lexer" }
|
||||||
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
rustc_lint_defs = { path = "../rustc_lint_defs" }
|
||||||
rustc_macros = { path = "../rustc_macros" }
|
rustc_macros = { path = "../rustc_macros" }
|
||||||
|
|
|
@ -2,9 +2,10 @@ use rustc_ast as ast;
|
||||||
use rustc_ast::ptr::P;
|
use rustc_ast::ptr::P;
|
||||||
use rustc_ast::token::{self, Delimiter};
|
use rustc_ast::token::{self, Delimiter};
|
||||||
use rustc_ast::tokenstream::TokenStream;
|
use rustc_ast::tokenstream::TokenStream;
|
||||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
|
||||||
use rustc_errors::PResult;
|
use rustc_errors::PResult;
|
||||||
use rustc_expand::base::{self, *};
|
use rustc_expand::base::{self, *};
|
||||||
|
use rustc_index::bit_set::GrowableBitSet;
|
||||||
use rustc_parse::parser::Parser;
|
use rustc_parse::parser::Parser;
|
||||||
use rustc_parse_format as parse;
|
use rustc_parse_format as parse;
|
||||||
use rustc_session::lint;
|
use rustc_session::lint;
|
||||||
|
@ -20,8 +21,8 @@ use crate::errors;
|
||||||
pub struct AsmArgs {
|
pub struct AsmArgs {
|
||||||
pub templates: Vec<P<ast::Expr>>,
|
pub templates: Vec<P<ast::Expr>>,
|
||||||
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
|
pub operands: Vec<(ast::InlineAsmOperand, Span)>,
|
||||||
named_args: FxHashMap<Symbol, usize>,
|
named_args: FxIndexMap<Symbol, usize>,
|
||||||
reg_args: FxHashSet<usize>,
|
reg_args: GrowableBitSet<usize>,
|
||||||
pub clobber_abis: Vec<(Symbol, Span)>,
|
pub clobber_abis: Vec<(Symbol, Span)>,
|
||||||
options: ast::InlineAsmOptions,
|
options: ast::InlineAsmOptions,
|
||||||
pub options_spans: Vec<Span>,
|
pub options_spans: Vec<Span>,
|
||||||
|
@ -56,8 +57,8 @@ pub fn parse_asm_args<'a>(
|
||||||
let mut args = AsmArgs {
|
let mut args = AsmArgs {
|
||||||
templates: vec![first_template],
|
templates: vec![first_template],
|
||||||
operands: vec![],
|
operands: vec![],
|
||||||
named_args: FxHashMap::default(),
|
named_args: Default::default(),
|
||||||
reg_args: FxHashSet::default(),
|
reg_args: Default::default(),
|
||||||
clobber_abis: Vec::new(),
|
clobber_abis: Vec::new(),
|
||||||
options: ast::InlineAsmOptions::empty(),
|
options: ast::InlineAsmOptions::empty(),
|
||||||
options_spans: vec![],
|
options_spans: vec![],
|
||||||
|
@ -213,7 +214,7 @@ pub fn parse_asm_args<'a>(
|
||||||
} else {
|
} else {
|
||||||
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
|
if !args.named_args.is_empty() || !args.reg_args.is_empty() {
|
||||||
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
|
let named = args.named_args.values().map(|p| args.operands[*p].1).collect();
|
||||||
let explicit = args.reg_args.iter().map(|p| args.operands[*p].1).collect();
|
let explicit = args.reg_args.iter().map(|p| args.operands[p].1).collect();
|
||||||
|
|
||||||
diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
|
diag.emit_err(errors::AsmPositionalAfter { span, named, explicit });
|
||||||
}
|
}
|
||||||
|
@ -446,8 +447,8 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
||||||
// Register operands are implicitly used since they are not allowed to be
|
// Register operands are implicitly used since they are not allowed to be
|
||||||
// referenced in the template string.
|
// referenced in the template string.
|
||||||
let mut used = vec![false; args.operands.len()];
|
let mut used = vec![false; args.operands.len()];
|
||||||
for pos in &args.reg_args {
|
for pos in args.reg_args.iter() {
|
||||||
used[*pos] = true;
|
used[pos] = true;
|
||||||
}
|
}
|
||||||
let named_pos: FxHashMap<usize, Symbol> =
|
let named_pos: FxHashMap<usize, Symbol> =
|
||||||
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
|
args.named_args.iter().map(|(&sym, &idx)| (idx, sym)).collect();
|
||||||
|
@ -581,7 +582,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
||||||
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
|
parse::ArgumentIs(idx) | parse::ArgumentImplicitlyIs(idx) => {
|
||||||
if idx >= args.operands.len()
|
if idx >= args.operands.len()
|
||||||
|| named_pos.contains_key(&idx)
|
|| named_pos.contains_key(&idx)
|
||||||
|| args.reg_args.contains(&idx)
|
|| args.reg_args.contains(idx)
|
||||||
{
|
{
|
||||||
let msg = format!("invalid reference to argument at index {}", idx);
|
let msg = format!("invalid reference to argument at index {}", idx);
|
||||||
let mut err = ecx.struct_span_err(span, &msg);
|
let mut err = ecx.struct_span_err(span, &msg);
|
||||||
|
@ -608,7 +609,7 @@ fn expand_preparsed_asm(ecx: &mut ExtCtxt<'_>, args: AsmArgs) -> Option<ast::Inl
|
||||||
args.operands[idx].1,
|
args.operands[idx].1,
|
||||||
"named arguments cannot be referenced by position",
|
"named arguments cannot be referenced by position",
|
||||||
);
|
);
|
||||||
} else if args.reg_args.contains(&idx) {
|
} else if args.reg_args.contains(idx) {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
args.operands[idx].1,
|
args.operands[idx].1,
|
||||||
"explicit register argument",
|
"explicit register argument",
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
//! This crate contains implementations of built-in macros and other code generating facilities
|
//! This crate contains implementations of built-in macros and other code generating facilities
|
||||||
//! injecting code into the crate before it is lowered to HIR.
|
//! injecting code into the crate before it is lowered to HIR.
|
||||||
|
|
||||||
#![allow(rustc::potential_query_instability)]
|
|
||||||
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
|
||||||
#![feature(array_windows)]
|
#![feature(array_windows)]
|
||||||
#![feature(box_patterns)]
|
#![feature(box_patterns)]
|
||||||
|
|
|
@ -64,6 +64,11 @@ impl Fingerprint {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub(crate) fn as_u128(self) -> u128 {
|
||||||
|
u128::from(self.1) << 64 | u128::from(self.0)
|
||||||
|
}
|
||||||
|
|
||||||
// Combines two hashes in an order independent way. Make sure this is what
|
// Combines two hashes in an order independent way. Make sure this is what
|
||||||
// you want.
|
// you want.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -23,18 +23,18 @@ impl Svh {
|
||||||
Svh { hash }
|
Svh { hash }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_u64(&self) -> u64 {
|
pub fn as_u128(self) -> u128 {
|
||||||
self.hash.to_smaller_hash().as_u64()
|
self.hash.as_u128()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn to_string(&self) -> String {
|
pub fn to_hex(self) -> String {
|
||||||
format!("{:016x}", self.hash.to_smaller_hash())
|
format!("{:032x}", self.hash.as_u128())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Svh {
|
impl fmt::Display for Svh {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
f.pad(&self.to_string())
|
f.pad(&self.to_hex())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -280,3 +280,7 @@ hir_analysis_const_specialize = cannot specialize on const impl with non-const i
|
||||||
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
|
hir_analysis_static_specialize = cannot specialize on `'static` lifetime
|
||||||
|
|
||||||
hir_analysis_missing_tilde_const = missing `~const` qualifier for specialization
|
hir_analysis_missing_tilde_const = missing `~const` qualifier for specialization
|
||||||
|
|
||||||
|
hir_analysis_drop_impl_negative = negative `Drop` impls are not supported
|
||||||
|
|
||||||
|
hir_analysis_drop_impl_reservation = reservation `Drop` impls are not supported
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
|
// FIXME(@lcnr): Move this module out of `rustc_hir_analysis`.
|
||||||
//
|
//
|
||||||
// We don't do any drop checking during hir typeck.
|
// We don't do any drop checking during hir typeck.
|
||||||
use crate::hir::def_id::{DefId, LocalDefId};
|
|
||||||
use rustc_errors::{struct_span_err, ErrorGuaranteed};
|
use rustc_errors::{struct_span_err, ErrorGuaranteed};
|
||||||
use rustc_middle::ty::error::TypeError;
|
use rustc_middle::ty::error::TypeError;
|
||||||
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
use rustc_middle::ty::relate::{Relate, RelateResult, TypeRelation};
|
||||||
|
@ -9,6 +8,9 @@ use rustc_middle::ty::subst::SubstsRef;
|
||||||
use rustc_middle::ty::util::IgnoreRegions;
|
use rustc_middle::ty::util::IgnoreRegions;
|
||||||
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
|
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
|
||||||
|
|
||||||
|
use crate::errors;
|
||||||
|
use crate::hir::def_id::{DefId, LocalDefId};
|
||||||
|
|
||||||
/// This function confirms that the `Drop` implementation identified by
|
/// This function confirms that the `Drop` implementation identified by
|
||||||
/// `drop_impl_did` is not any more specialized than the type it is
|
/// `drop_impl_did` is not any more specialized than the type it is
|
||||||
/// attached to (Issue #8142).
|
/// attached to (Issue #8142).
|
||||||
|
@ -27,6 +29,19 @@ use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
|
||||||
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
|
/// cannot do `struct S<T>; impl<T:Clone> Drop for S<T> { ... }`).
|
||||||
///
|
///
|
||||||
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
|
pub fn check_drop_impl(tcx: TyCtxt<'_>, drop_impl_did: DefId) -> Result<(), ErrorGuaranteed> {
|
||||||
|
match tcx.impl_polarity(drop_impl_did) {
|
||||||
|
ty::ImplPolarity::Positive => {}
|
||||||
|
ty::ImplPolarity::Negative => {
|
||||||
|
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Negative {
|
||||||
|
span: tcx.def_span(drop_impl_did),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
ty::ImplPolarity::Reservation => {
|
||||||
|
return Err(tcx.sess.emit_err(errors::DropImplPolarity::Reservation {
|
||||||
|
span: tcx.def_span(drop_impl_did),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
let dtor_self_type = tcx.type_of(drop_impl_did).subst_identity();
|
let dtor_self_type = tcx.type_of(drop_impl_did).subst_identity();
|
||||||
let dtor_predicates = tcx.predicates_of(drop_impl_did);
|
let dtor_predicates = tcx.predicates_of(drop_impl_did);
|
||||||
match dtor_self_type.kind() {
|
match dtor_self_type.kind() {
|
||||||
|
|
|
@ -823,3 +823,17 @@ pub(crate) struct MissingTildeConst {
|
||||||
#[primary_span]
|
#[primary_span]
|
||||||
pub span: Span,
|
pub span: Span,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Diagnostic)]
|
||||||
|
pub(crate) enum DropImplPolarity {
|
||||||
|
#[diag(hir_analysis_drop_impl_negative)]
|
||||||
|
Negative {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
#[diag(hir_analysis_drop_impl_reservation)]
|
||||||
|
Reservation {
|
||||||
|
#[primary_span]
|
||||||
|
span: Span,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
|
@ -346,7 +346,7 @@ pub fn finalize_session_directory(sess: &Session, svh: Option<Svh>) {
|
||||||
let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]);
|
let mut new_sub_dir_name = String::from(&old_sub_dir_name[..=dash_indices[2]]);
|
||||||
|
|
||||||
// Append the svh
|
// Append the svh
|
||||||
base_n::push_str(svh.as_u64() as u128, INT_ENCODE_BASE, &mut new_sub_dir_name);
|
base_n::push_str(svh.as_u128(), INT_ENCODE_BASE, &mut new_sub_dir_name);
|
||||||
|
|
||||||
// Create the full path
|
// Create the full path
|
||||||
let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name);
|
let new_path = incr_comp_session_dir.parent().unwrap().join(new_sub_dir_name);
|
||||||
|
|
|
@ -837,11 +837,12 @@ fn should_encode_span(def_kind: DefKind) -> bool {
|
||||||
| DefKind::AnonConst
|
| DefKind::AnonConst
|
||||||
| DefKind::InlineConst
|
| DefKind::InlineConst
|
||||||
| DefKind::OpaqueTy
|
| DefKind::OpaqueTy
|
||||||
|
| DefKind::ImplTraitPlaceholder
|
||||||
| DefKind::Field
|
| DefKind::Field
|
||||||
| DefKind::Impl { .. }
|
| DefKind::Impl { .. }
|
||||||
| DefKind::Closure
|
| DefKind::Closure
|
||||||
| DefKind::Generator => true,
|
| DefKind::Generator => true,
|
||||||
DefKind::ForeignMod | DefKind::ImplTraitPlaceholder | DefKind::GlobalAsm => false,
|
DefKind::ForeignMod | DefKind::GlobalAsm => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
|
Err(e) => self.tcx.const_error_with_guaranteed(c.ty(), e),
|
||||||
Ok(Some(bac)) => {
|
Ok(Some(bac)) => {
|
||||||
let substs = self.tcx.erase_regions(uv.substs);
|
let substs = self.tcx.erase_regions(uv.substs);
|
||||||
bac.subst(self.tcx, substs)
|
let bac = bac.subst(self.tcx, substs);
|
||||||
|
return bac.fold_with(self);
|
||||||
}
|
}
|
||||||
Ok(None) => c,
|
Ok(None) => c,
|
||||||
},
|
},
|
||||||
|
|
|
@ -360,16 +360,16 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
let ty = self.type_of(adt_did).subst_identity();
|
let ty = self.type_of(adt_did).subst_identity();
|
||||||
let mut dtor_candidate = None;
|
let mut dtor_candidate = None;
|
||||||
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
|
self.for_each_relevant_impl(drop_trait, ty, |impl_did| {
|
||||||
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
|
|
||||||
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
|
|
||||||
return;
|
|
||||||
};
|
|
||||||
|
|
||||||
if validate(self, impl_did).is_err() {
|
if validate(self, impl_did).is_err() {
|
||||||
// Already `ErrorGuaranteed`, no need to delay a span bug here.
|
// Already `ErrorGuaranteed`, no need to delay a span bug here.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let Some(item_id) = self.associated_item_def_ids(impl_did).first() else {
|
||||||
|
self.sess.delay_span_bug(self.def_span(impl_did), "Drop impl without drop function");
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
|
||||||
if let Some((old_item_id, _)) = dtor_candidate {
|
if let Some((old_item_id, _)) = dtor_candidate {
|
||||||
self.sess
|
self.sess
|
||||||
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
|
.struct_span_err(self.def_span(item_id), "multiple drop impls found")
|
||||||
|
|
|
@ -550,7 +550,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
let sm = self.tcx.sess.source_map();
|
let sm = self.tcx.sess.source_map();
|
||||||
let def_id = match outer_res {
|
let def_id = match outer_res {
|
||||||
Res::SelfTyParam { .. } => {
|
Res::SelfTyParam { .. } | Res::SelfCtor(_) => {
|
||||||
err.span_label(span, "can't use `Self` here");
|
err.span_label(span, "can't use `Self` here");
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,6 @@ use crate::{ResolutionError, Resolver, Scope, ScopeSet, Segment, ToNameBinding,
|
||||||
|
|
||||||
use Determinacy::*;
|
use Determinacy::*;
|
||||||
use Namespace::*;
|
use Namespace::*;
|
||||||
use RibKind::*;
|
|
||||||
|
|
||||||
type Visibility = ty::Visibility<LocalDefId>;
|
type Visibility = ty::Visibility<LocalDefId>;
|
||||||
|
|
||||||
|
@ -324,8 +323,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
module = match ribs[i].kind {
|
module = match ribs[i].kind {
|
||||||
ModuleRibKind(module) => module,
|
RibKind::Module(module) => module,
|
||||||
MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => {
|
RibKind::MacroDefinition(def) if def == self.macro_def(ident.span.ctxt()) => {
|
||||||
// If an invocation of this macro created `ident`, give up on `ident`
|
// If an invocation of this macro created `ident`, give up on `ident`
|
||||||
// and switch to `ident`'s source from the macro definition.
|
// and switch to `ident`'s source from the macro definition.
|
||||||
ident.span.remove_mark();
|
ident.span.remove_mark();
|
||||||
|
@ -1084,7 +1083,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
let ribs = &all_ribs[rib_index + 1..];
|
let ribs = &all_ribs[rib_index + 1..];
|
||||||
|
|
||||||
// An invalid forward use of a generic parameter from a previous default.
|
// An invalid forward use of a generic parameter from a previous default.
|
||||||
if let ForwardGenericParamBanRibKind = all_ribs[rib_index].kind {
|
if let RibKind::ForwardGenericParamBan = all_ribs[rib_index].kind {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
let res_error = if rib_ident.name == kw::SelfUpper {
|
let res_error = if rib_ident.name == kw::SelfUpper {
|
||||||
ResolutionError::SelfInGenericParamDefault
|
ResolutionError::SelfInGenericParamDefault
|
||||||
|
@ -1104,14 +1103,14 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
|
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
match rib.kind {
|
match rib.kind {
|
||||||
NormalRibKind
|
RibKind::Normal
|
||||||
| ClosureOrAsyncRibKind
|
| RibKind::ClosureOrAsync
|
||||||
| ModuleRibKind(..)
|
| RibKind::Module(..)
|
||||||
| MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| ForwardGenericParamBanRibKind => {
|
| RibKind::ForwardGenericParamBan => {
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
}
|
}
|
||||||
ItemRibKind(_) | AssocItemRibKind => {
|
RibKind::Item(_) | RibKind::AssocItem => {
|
||||||
// This was an attempt to access an upvar inside a
|
// This was an attempt to access an upvar inside a
|
||||||
// named function item. This is not allowed, so we
|
// named function item. This is not allowed, so we
|
||||||
// report an error.
|
// report an error.
|
||||||
|
@ -1123,7 +1122,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
res_err = Some((span, CannotCaptureDynamicEnvironmentInFnItem));
|
res_err = Some((span, CannotCaptureDynamicEnvironmentInFnItem));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ConstantItemRibKind(_, item) => {
|
RibKind::ConstantItem(_, item) => {
|
||||||
// Still doesn't deal with upvars
|
// Still doesn't deal with upvars
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
let (span, resolution_error) =
|
let (span, resolution_error) =
|
||||||
|
@ -1152,13 +1151,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
ConstParamTyRibKind => {
|
RibKind::ConstParamTy => {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
self.report_error(span, ParamInTyOfConstParam(rib_ident.name));
|
self.report_error(span, ParamInTyOfConstParam(rib_ident.name));
|
||||||
}
|
}
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
InlineAsmSymRibKind => {
|
RibKind::InlineAsmSym => {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
self.report_error(span, InvalidAsmSym);
|
self.report_error(span, InvalidAsmSym);
|
||||||
}
|
}
|
||||||
|
@ -1171,21 +1170,24 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
return Res::Err;
|
return Res::Err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Res::Def(DefKind::TyParam, _) | Res::SelfTyParam { .. } | Res::SelfTyAlias { .. } => {
|
Res::Def(DefKind::TyParam, _)
|
||||||
|
| Res::SelfTyParam { .. }
|
||||||
|
| Res::SelfTyAlias { .. }
|
||||||
|
| Res::SelfCtor(_) => {
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
let has_generic_params: HasGenericParams = match rib.kind {
|
let has_generic_params: HasGenericParams = match rib.kind {
|
||||||
NormalRibKind
|
RibKind::Normal
|
||||||
| ClosureOrAsyncRibKind
|
| RibKind::ClosureOrAsync
|
||||||
| ModuleRibKind(..)
|
| RibKind::Module(..)
|
||||||
| MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| InlineAsmSymRibKind
|
| RibKind::InlineAsmSym
|
||||||
| AssocItemRibKind
|
| RibKind::AssocItem
|
||||||
| ForwardGenericParamBanRibKind => {
|
| RibKind::ForwardGenericParamBan => {
|
||||||
// Nothing to do. Continue.
|
// Nothing to do. Continue.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ConstantItemRibKind(trivial, _) => {
|
RibKind::ConstantItem(trivial, _) => {
|
||||||
let features = self.tcx.sess.features_untracked();
|
let features = self.tcx.sess.features_untracked();
|
||||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||||
if !(trivial == ConstantHasGenerics::Yes
|
if !(trivial == ConstantHasGenerics::Yes
|
||||||
|
@ -1226,8 +1228,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This was an attempt to use a type parameter outside its scope.
|
// This was an attempt to use a type parameter outside its scope.
|
||||||
ItemRibKind(has_generic_params) => has_generic_params,
|
RibKind::Item(has_generic_params) => has_generic_params,
|
||||||
ConstParamTyRibKind => {
|
RibKind::ConstParamTy => {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
span,
|
span,
|
||||||
|
@ -1253,15 +1255,15 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
Res::Def(DefKind::ConstParam, _) => {
|
Res::Def(DefKind::ConstParam, _) => {
|
||||||
for rib in ribs {
|
for rib in ribs {
|
||||||
let has_generic_params = match rib.kind {
|
let has_generic_params = match rib.kind {
|
||||||
NormalRibKind
|
RibKind::Normal
|
||||||
| ClosureOrAsyncRibKind
|
| RibKind::ClosureOrAsync
|
||||||
| ModuleRibKind(..)
|
| RibKind::Module(..)
|
||||||
| MacroDefinition(..)
|
| RibKind::MacroDefinition(..)
|
||||||
| InlineAsmSymRibKind
|
| RibKind::InlineAsmSym
|
||||||
| AssocItemRibKind
|
| RibKind::AssocItem
|
||||||
| ForwardGenericParamBanRibKind => continue,
|
| RibKind::ForwardGenericParamBan => continue,
|
||||||
|
|
||||||
ConstantItemRibKind(trivial, _) => {
|
RibKind::ConstantItem(trivial, _) => {
|
||||||
let features = self.tcx.sess.features_untracked();
|
let features = self.tcx.sess.features_untracked();
|
||||||
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
// HACK(min_const_generics): We currently only allow `N` or `{ N }`.
|
||||||
if !(trivial == ConstantHasGenerics::Yes
|
if !(trivial == ConstantHasGenerics::Yes
|
||||||
|
@ -1284,8 +1286,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemRibKind(has_generic_params) => has_generic_params,
|
RibKind::Item(has_generic_params) => has_generic_params,
|
||||||
ConstParamTyRibKind => {
|
RibKind::ConstParamTy => {
|
||||||
if let Some(span) = finalize {
|
if let Some(span) = finalize {
|
||||||
self.report_error(
|
self.report_error(
|
||||||
span,
|
span,
|
||||||
|
|
|
@ -6,8 +6,6 @@
|
||||||
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
|
//! If you wonder why there's no `early.rs`, that's because it's split into three files -
|
||||||
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
|
//! `build_reduced_graph.rs`, `macros.rs` and `imports.rs`.
|
||||||
|
|
||||||
use RibKind::*;
|
|
||||||
|
|
||||||
use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
use crate::{path_names_to_string, rustdoc, BindingError, Finalize, LexicalScopeBinding};
|
||||||
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult};
|
use crate::{Module, ModuleOrUniformRoot, NameBinding, ParentScope, PathResult};
|
||||||
use crate::{ResolutionError, Resolver, Segment, UseError};
|
use crate::{ResolutionError, Resolver, Segment, UseError};
|
||||||
|
@ -133,28 +131,28 @@ enum RecordPartialRes {
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) enum RibKind<'a> {
|
pub(crate) enum RibKind<'a> {
|
||||||
/// No restriction needs to be applied.
|
/// No restriction needs to be applied.
|
||||||
NormalRibKind,
|
Normal,
|
||||||
|
|
||||||
/// We passed through an impl or trait and are now in one of its
|
/// We passed through an impl or trait and are now in one of its
|
||||||
/// methods or associated types. Allow references to ty params that impl or trait
|
/// methods or associated types. Allow references to ty params that impl or trait
|
||||||
/// binds. Disallow any other upvars (including other ty params that are
|
/// binds. Disallow any other upvars (including other ty params that are
|
||||||
/// upvars).
|
/// upvars).
|
||||||
AssocItemRibKind,
|
AssocItem,
|
||||||
|
|
||||||
/// We passed through a closure. Disallow labels.
|
/// We passed through a closure. Disallow labels.
|
||||||
ClosureOrAsyncRibKind,
|
ClosureOrAsync,
|
||||||
|
|
||||||
/// We passed through an item scope. Disallow upvars.
|
/// We passed through an item scope. Disallow upvars.
|
||||||
ItemRibKind(HasGenericParams),
|
Item(HasGenericParams),
|
||||||
|
|
||||||
/// We're in a constant item. Can't refer to dynamic stuff.
|
/// We're in a constant item. Can't refer to dynamic stuff.
|
||||||
///
|
///
|
||||||
/// The item may reference generic parameters in trivial constant expressions.
|
/// The item may reference generic parameters in trivial constant expressions.
|
||||||
/// All other constants aren't allowed to use generic params at all.
|
/// All other constants aren't allowed to use generic params at all.
|
||||||
ConstantItemRibKind(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>),
|
ConstantItem(ConstantHasGenerics, Option<(Ident, ConstantItemKind)>),
|
||||||
|
|
||||||
/// We passed through a module.
|
/// We passed through a module.
|
||||||
ModuleRibKind(Module<'a>),
|
Module(Module<'a>),
|
||||||
|
|
||||||
/// We passed through a `macro_rules!` statement
|
/// We passed through a `macro_rules!` statement
|
||||||
MacroDefinition(DefId),
|
MacroDefinition(DefId),
|
||||||
|
@ -162,15 +160,15 @@ pub(crate) enum RibKind<'a> {
|
||||||
/// All bindings in this rib are generic parameters that can't be used
|
/// All bindings in this rib are generic parameters that can't be used
|
||||||
/// from the default of a generic parameter because they're not declared
|
/// from the default of a generic parameter because they're not declared
|
||||||
/// before said generic parameter. Also see the `visit_generics` override.
|
/// before said generic parameter. Also see the `visit_generics` override.
|
||||||
ForwardGenericParamBanRibKind,
|
ForwardGenericParamBan,
|
||||||
|
|
||||||
/// We are inside of the type of a const parameter. Can't refer to any
|
/// We are inside of the type of a const parameter. Can't refer to any
|
||||||
/// parameters.
|
/// parameters.
|
||||||
ConstParamTyRibKind,
|
ConstParamTy,
|
||||||
|
|
||||||
/// We are inside a `sym` inline assembly operand. Can only refer to
|
/// We are inside a `sym` inline assembly operand. Can only refer to
|
||||||
/// globals.
|
/// globals.
|
||||||
InlineAsmSymRibKind,
|
InlineAsmSym,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RibKind<'_> {
|
impl RibKind<'_> {
|
||||||
|
@ -178,30 +176,30 @@ impl RibKind<'_> {
|
||||||
/// variables.
|
/// variables.
|
||||||
pub(crate) fn contains_params(&self) -> bool {
|
pub(crate) fn contains_params(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
NormalRibKind
|
RibKind::Normal
|
||||||
| ClosureOrAsyncRibKind
|
| RibKind::ClosureOrAsync
|
||||||
| ConstantItemRibKind(..)
|
| RibKind::ConstantItem(..)
|
||||||
| ModuleRibKind(_)
|
| RibKind::Module(_)
|
||||||
| MacroDefinition(_)
|
| RibKind::MacroDefinition(_)
|
||||||
| ConstParamTyRibKind
|
| RibKind::ConstParamTy
|
||||||
| InlineAsmSymRibKind => false,
|
| RibKind::InlineAsmSym => false,
|
||||||
AssocItemRibKind | ItemRibKind(_) | ForwardGenericParamBanRibKind => true,
|
RibKind::AssocItem | RibKind::Item(_) | RibKind::ForwardGenericParamBan => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This rib forbids referring to labels defined in upwards ribs.
|
/// This rib forbids referring to labels defined in upwards ribs.
|
||||||
fn is_label_barrier(self) -> bool {
|
fn is_label_barrier(self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
NormalRibKind | MacroDefinition(..) => false,
|
RibKind::Normal | RibKind::MacroDefinition(..) => false,
|
||||||
|
|
||||||
AssocItemRibKind
|
RibKind::AssocItem
|
||||||
| ClosureOrAsyncRibKind
|
| RibKind::ClosureOrAsync
|
||||||
| ItemRibKind(..)
|
| RibKind::Item(..)
|
||||||
| ConstantItemRibKind(..)
|
| RibKind::ConstantItem(..)
|
||||||
| ModuleRibKind(..)
|
| RibKind::Module(..)
|
||||||
| ForwardGenericParamBanRibKind
|
| RibKind::ForwardGenericParamBan
|
||||||
| ConstParamTyRibKind
|
| RibKind::ConstParamTy
|
||||||
| InlineAsmSymRibKind => true,
|
| RibKind::InlineAsmSym => true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -702,7 +700,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
let span = ty.span.shrink_to_lo().to(path.span.shrink_to_lo());
|
let span = ty.span.shrink_to_lo().to(path.span.shrink_to_lo());
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&[],
|
&[],
|
||||||
NormalRibKind,
|
RibKind::Normal,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: ty.id,
|
binder: ty.id,
|
||||||
kind: LifetimeBinderKind::PolyTrait,
|
kind: LifetimeBinderKind::PolyTrait,
|
||||||
|
@ -740,7 +738,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());
|
let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo());
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&bare_fn.generic_params,
|
&bare_fn.generic_params,
|
||||||
NormalRibKind,
|
RibKind::Normal,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: ty.id,
|
binder: ty.id,
|
||||||
kind: LifetimeBinderKind::BareFnType,
|
kind: LifetimeBinderKind::BareFnType,
|
||||||
|
@ -780,7 +778,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
|
let span = tref.span.shrink_to_lo().to(tref.trait_ref.path.span.shrink_to_lo());
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&tref.bound_generic_params,
|
&tref.bound_generic_params,
|
||||||
NormalRibKind,
|
RibKind::Normal,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: tref.trait_ref.ref_id,
|
binder: tref.trait_ref.ref_id,
|
||||||
kind: LifetimeBinderKind::PolyTrait,
|
kind: LifetimeBinderKind::PolyTrait,
|
||||||
|
@ -804,7 +802,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
ForeignItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: foreign_item.id,
|
binder: foreign_item.id,
|
||||||
kind: LifetimeBinderKind::Item,
|
kind: LifetimeBinderKind::Item,
|
||||||
|
@ -816,7 +814,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
|
ForeignItemKind::Fn(box Fn { ref generics, .. }) => {
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: foreign_item.id,
|
binder: foreign_item.id,
|
||||||
kind: LifetimeBinderKind::Function,
|
kind: LifetimeBinderKind::Function,
|
||||||
|
@ -870,9 +868,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
debug!("(resolving function) entering function");
|
debug!("(resolving function) entering function");
|
||||||
|
|
||||||
// Create a value rib for the function.
|
// Create a value rib for the function.
|
||||||
self.with_rib(ValueNS, ClosureOrAsyncRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::ClosureOrAsync, |this| {
|
||||||
// Create a label rib for the function.
|
// Create a label rib for the function.
|
||||||
this.with_label_rib(ClosureOrAsyncRibKind, |this| {
|
this.with_label_rib(RibKind::ClosureOrAsync, |this| {
|
||||||
match fn_kind {
|
match fn_kind {
|
||||||
FnKind::Fn(_, _, sig, _, generics, body) => {
|
FnKind::Fn(_, _, sig, _, generics, body) => {
|
||||||
this.visit_generics(generics);
|
this.visit_generics(generics);
|
||||||
|
@ -1129,7 +1127,7 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
let span = predicate_span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
|
let span = predicate_span.shrink_to_lo().to(bounded_ty.span.shrink_to_lo());
|
||||||
this.with_generic_param_rib(
|
this.with_generic_param_rib(
|
||||||
&bound_generic_params,
|
&bound_generic_params,
|
||||||
NormalRibKind,
|
RibKind::Normal,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: bounded_ty.id,
|
binder: bounded_ty.id,
|
||||||
kind: LifetimeBinderKind::WhereBound,
|
kind: LifetimeBinderKind::WhereBound,
|
||||||
|
@ -1175,9 +1173,9 @@ impl<'a: 'ast, 'ast, 'tcx> Visitor<'ast> for LateResolutionVisitor<'a, '_, 'ast,
|
||||||
|
|
||||||
fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
|
fn visit_inline_asm_sym(&mut self, sym: &'ast InlineAsmSym) {
|
||||||
// This is similar to the code for AnonConst.
|
// This is similar to the code for AnonConst.
|
||||||
self.with_rib(ValueNS, InlineAsmSymRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::InlineAsmSym, |this| {
|
||||||
this.with_rib(TypeNS, InlineAsmSymRibKind, |this| {
|
this.with_rib(TypeNS, RibKind::InlineAsmSym, |this| {
|
||||||
this.with_label_rib(InlineAsmSymRibKind, |this| {
|
this.with_label_rib(RibKind::InlineAsmSym, |this| {
|
||||||
this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None));
|
this.smart_resolve_path(sym.id, &sym.qself, &sym.path, PathSource::Expr(None));
|
||||||
visit::walk_inline_asm_sym(this, sym);
|
visit::walk_inline_asm_sym(this, sym);
|
||||||
});
|
});
|
||||||
|
@ -1202,7 +1200,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// although it may be useful to track other components as well for diagnostics.
|
// although it may be useful to track other components as well for diagnostics.
|
||||||
let graph_root = resolver.graph_root;
|
let graph_root = resolver.graph_root;
|
||||||
let parent_scope = ParentScope::module(graph_root, resolver);
|
let parent_scope = ParentScope::module(graph_root, resolver);
|
||||||
let start_rib_kind = ModuleRibKind(graph_root);
|
let start_rib_kind = RibKind::Module(graph_root);
|
||||||
LateResolutionVisitor {
|
LateResolutionVisitor {
|
||||||
r: resolver,
|
r: resolver,
|
||||||
parent_scope,
|
parent_scope,
|
||||||
|
@ -1306,8 +1304,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
|
if let Some(module) = self.r.get_module(self.r.local_def_id(id).to_def_id()) {
|
||||||
// Move down in the graph.
|
// Move down in the graph.
|
||||||
let orig_module = replace(&mut self.parent_scope.module, module);
|
let orig_module = replace(&mut self.parent_scope.module, module);
|
||||||
self.with_rib(ValueNS, ModuleRibKind(module), |this| {
|
self.with_rib(ValueNS, RibKind::Module(module), |this| {
|
||||||
this.with_rib(TypeNS, ModuleRibKind(module), |this| {
|
this.with_rib(TypeNS, RibKind::Module(module), |this| {
|
||||||
let ret = f(this);
|
let ret = f(this);
|
||||||
this.parent_scope.module = orig_module;
|
this.parent_scope.module = orig_module;
|
||||||
ret
|
ret
|
||||||
|
@ -1324,8 +1322,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// provide previous type parameters as they're built. We
|
// provide previous type parameters as they're built. We
|
||||||
// put all the parameters on the ban list and then remove
|
// put all the parameters on the ban list and then remove
|
||||||
// them one by one as they are processed and become available.
|
// them one by one as they are processed and become available.
|
||||||
let mut forward_ty_ban_rib = Rib::new(ForwardGenericParamBanRibKind);
|
let mut forward_ty_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
||||||
let mut forward_const_ban_rib = Rib::new(ForwardGenericParamBanRibKind);
|
let mut forward_const_ban_rib = Rib::new(RibKind::ForwardGenericParamBan);
|
||||||
for param in params.iter() {
|
for param in params.iter() {
|
||||||
match param.kind {
|
match param.kind {
|
||||||
GenericParamKind::Type { .. } => {
|
GenericParamKind::Type { .. } => {
|
||||||
|
@ -1386,8 +1384,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// Const parameters can't have param bounds.
|
// Const parameters can't have param bounds.
|
||||||
assert!(param.bounds.is_empty());
|
assert!(param.bounds.is_empty());
|
||||||
|
|
||||||
this.ribs[TypeNS].push(Rib::new(ConstParamTyRibKind));
|
this.ribs[TypeNS].push(Rib::new(RibKind::ConstParamTy));
|
||||||
this.ribs[ValueNS].push(Rib::new(ConstParamTyRibKind));
|
this.ribs[ValueNS].push(Rib::new(RibKind::ConstParamTy));
|
||||||
this.with_lifetime_rib(LifetimeRibKind::ConstGeneric, |this| {
|
this.with_lifetime_rib(LifetimeRibKind::ConstGeneric, |this| {
|
||||||
this.visit_ty(ty)
|
this.visit_ty(ty)
|
||||||
});
|
});
|
||||||
|
@ -2109,7 +2107,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
for i in (0..self.label_ribs.len()).rev() {
|
for i in (0..self.label_ribs.len()).rev() {
|
||||||
let rib = &self.label_ribs[i];
|
let rib = &self.label_ribs[i];
|
||||||
|
|
||||||
if let MacroDefinition(def) = rib.kind {
|
if let RibKind::MacroDefinition(def) = rib.kind {
|
||||||
// If an invocation of this macro created `ident`, give up on `ident`
|
// If an invocation of this macro created `ident`, give up on `ident`
|
||||||
// and switch to `ident`'s source from the macro definition.
|
// and switch to `ident`'s source from the macro definition.
|
||||||
if def == self.r.macro_def(label.span.ctxt()) {
|
if def == self.r.macro_def(label.span.ctxt()) {
|
||||||
|
@ -2157,7 +2155,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
self.with_current_self_item(item, |this| {
|
self.with_current_self_item(item, |this| {
|
||||||
this.with_generic_param_rib(
|
this.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
kind: LifetimeBinderKind::Item,
|
kind: LifetimeBinderKind::Item,
|
||||||
|
@ -2238,7 +2236,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
ItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
ItemKind::TyAlias(box TyAlias { ref generics, .. }) => {
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
kind: LifetimeBinderKind::Item,
|
kind: LifetimeBinderKind::Item,
|
||||||
|
@ -2251,7 +2249,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
ItemKind::Fn(box Fn { ref generics, .. }) => {
|
ItemKind::Fn(box Fn { ref generics, .. }) => {
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
kind: LifetimeBinderKind::Function,
|
kind: LifetimeBinderKind::Function,
|
||||||
|
@ -2290,7 +2288,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// Create a new rib for the trait-wide type parameters.
|
// Create a new rib for the trait-wide type parameters.
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
kind: LifetimeBinderKind::Item,
|
kind: LifetimeBinderKind::Item,
|
||||||
|
@ -2311,7 +2309,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// Create a new rib for the trait-wide type parameters.
|
// Create a new rib for the trait-wide type parameters.
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
kind: LifetimeBinderKind::Item,
|
kind: LifetimeBinderKind::Item,
|
||||||
|
@ -2414,11 +2412,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
let mut seen_lifetimes = FxHashSet::default();
|
let mut seen_lifetimes = FxHashSet::default();
|
||||||
|
|
||||||
// We also can't shadow bindings from the parent item
|
// We also can't shadow bindings from the parent item
|
||||||
if let AssocItemRibKind = kind {
|
if let RibKind::AssocItem = kind {
|
||||||
let mut add_bindings_for_ns = |ns| {
|
let mut add_bindings_for_ns = |ns| {
|
||||||
let parent_rib = self.ribs[ns]
|
let parent_rib = self.ribs[ns]
|
||||||
.iter()
|
.iter()
|
||||||
.rfind(|r| matches!(r.kind, ItemRibKind(_)))
|
.rfind(|r| matches!(r.kind, RibKind::Item(_)))
|
||||||
.expect("associated item outside of an item");
|
.expect("associated item outside of an item");
|
||||||
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
|
seen_bindings.extend(parent_rib.bindings.keys().map(|ident| (*ident, ident.span)));
|
||||||
};
|
};
|
||||||
|
@ -2507,8 +2505,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let res = match kind {
|
let res = match kind {
|
||||||
ItemRibKind(..) | AssocItemRibKind => Res::Def(def_kind, def_id.to_def_id()),
|
RibKind::Item(..) | RibKind::AssocItem => Res::Def(def_kind, def_id.to_def_id()),
|
||||||
NormalRibKind => {
|
RibKind::Normal => {
|
||||||
if self.r.tcx.sess.features_untracked().non_lifetime_binders {
|
if self.r.tcx.sess.features_untracked().non_lifetime_binders {
|
||||||
Res::Def(def_kind, def_id.to_def_id())
|
Res::Def(def_kind, def_id.to_def_id())
|
||||||
} else {
|
} else {
|
||||||
|
@ -2554,7 +2552,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_static_rib(&mut self, f: impl FnOnce(&mut Self)) {
|
fn with_static_rib(&mut self, f: impl FnOnce(&mut Self)) {
|
||||||
let kind = ItemRibKind(HasGenericParams::No);
|
let kind = RibKind::Item(HasGenericParams::No);
|
||||||
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
|
self.with_rib(ValueNS, kind, |this| this.with_rib(TypeNS, kind, f))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2574,15 +2572,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
item: Option<(Ident, ConstantItemKind)>,
|
item: Option<(Ident, ConstantItemKind)>,
|
||||||
f: impl FnOnce(&mut Self),
|
f: impl FnOnce(&mut Self),
|
||||||
) {
|
) {
|
||||||
self.with_rib(ValueNS, ConstantItemRibKind(may_use_generics, item), |this| {
|
self.with_rib(ValueNS, RibKind::ConstantItem(may_use_generics, item), |this| {
|
||||||
this.with_rib(
|
this.with_rib(
|
||||||
TypeNS,
|
TypeNS,
|
||||||
ConstantItemRibKind(
|
RibKind::ConstantItem(
|
||||||
may_use_generics.force_yes_if(is_repeat == IsRepeatExpr::Yes),
|
may_use_generics.force_yes_if(is_repeat == IsRepeatExpr::Yes),
|
||||||
item,
|
item,
|
||||||
),
|
),
|
||||||
|this| {
|
|this| {
|
||||||
this.with_label_rib(ConstantItemRibKind(may_use_generics, item), f);
|
this.with_label_rib(RibKind::ConstantItem(may_use_generics, item), f);
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
@ -2614,7 +2612,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
|
|this: &mut Self, generics: &Generics, kind, item: &'ast AssocItem| {
|
||||||
this.with_generic_param_rib(
|
this.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
AssocItemRibKind,
|
RibKind::AssocItem,
|
||||||
LifetimeRibKind::Generics { binder: item.id, span: generics.span, kind },
|
LifetimeRibKind::Generics { binder: item.id, span: generics.span, kind },
|
||||||
|this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
|
|this| visit::walk_assoc_item(this, item, AssocCtxt::Trait),
|
||||||
);
|
);
|
||||||
|
@ -2695,7 +2693,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_self_rib_ns(&mut self, ns: Namespace, self_res: Res, f: impl FnOnce(&mut Self)) {
|
fn with_self_rib_ns(&mut self, ns: Namespace, self_res: Res, f: impl FnOnce(&mut Self)) {
|
||||||
let mut self_type_rib = Rib::new(NormalRibKind);
|
let mut self_type_rib = Rib::new(RibKind::Normal);
|
||||||
|
|
||||||
// Plain insert (no renaming, since types are not currently hygienic)
|
// Plain insert (no renaming, since types are not currently hygienic)
|
||||||
self_type_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), self_res);
|
self_type_rib.bindings.insert(Ident::with_dummy_span(kw::SelfUpper), self_res);
|
||||||
|
@ -2721,7 +2719,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// If applicable, create a rib for the type parameters.
|
// If applicable, create a rib for the type parameters.
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
ItemRibKind(HasGenericParams::Yes(generics.span)),
|
RibKind::Item(HasGenericParams::Yes(generics.span)),
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
span: generics.span,
|
span: generics.span,
|
||||||
binder: item_id,
|
binder: item_id,
|
||||||
|
@ -2835,7 +2833,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// We also need a new scope for the impl item type parameters.
|
// We also need a new scope for the impl item type parameters.
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
AssocItemRibKind,
|
RibKind::AssocItem,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
span: generics.span,
|
span: generics.span,
|
||||||
|
@ -2863,7 +2861,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
// We also need a new scope for the impl item type parameters.
|
// We also need a new scope for the impl item type parameters.
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generics.params,
|
&generics.params,
|
||||||
AssocItemRibKind,
|
RibKind::AssocItem,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: item.id,
|
binder: item.id,
|
||||||
span: generics.span,
|
span: generics.span,
|
||||||
|
@ -3135,7 +3133,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn resolve_arm(&mut self, arm: &'ast Arm) {
|
fn resolve_arm(&mut self, arm: &'ast Arm) {
|
||||||
self.with_rib(ValueNS, NormalRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||||
this.resolve_pattern_top(&arm.pat, PatternSource::Match);
|
this.resolve_pattern_top(&arm.pat, PatternSource::Match);
|
||||||
walk_list!(this, visit_expr, &arm.guard);
|
walk_list!(this, visit_expr, &arm.guard);
|
||||||
this.visit_expr(&arm.body);
|
this.visit_expr(&arm.body);
|
||||||
|
@ -3857,7 +3855,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
|
diagnostics::signal_label_shadowing(self.r.tcx.sess, orig_span, label.ident)
|
||||||
}
|
}
|
||||||
|
|
||||||
self.with_label_rib(NormalRibKind, |this| {
|
self.with_label_rib(RibKind::Normal, |this| {
|
||||||
let ident = label.ident.normalize_to_macro_rules();
|
let ident = label.ident.normalize_to_macro_rules();
|
||||||
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
|
this.label_ribs.last_mut().unwrap().bindings.insert(ident, id);
|
||||||
f(this);
|
f(this);
|
||||||
|
@ -3880,11 +3878,11 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
let mut num_macro_definition_ribs = 0;
|
let mut num_macro_definition_ribs = 0;
|
||||||
if let Some(anonymous_module) = anonymous_module {
|
if let Some(anonymous_module) = anonymous_module {
|
||||||
debug!("(resolving block) found anonymous module, moving down");
|
debug!("(resolving block) found anonymous module, moving down");
|
||||||
self.ribs[ValueNS].push(Rib::new(ModuleRibKind(anonymous_module)));
|
self.ribs[ValueNS].push(Rib::new(RibKind::Module(anonymous_module)));
|
||||||
self.ribs[TypeNS].push(Rib::new(ModuleRibKind(anonymous_module)));
|
self.ribs[TypeNS].push(Rib::new(RibKind::Module(anonymous_module)));
|
||||||
self.parent_scope.module = anonymous_module;
|
self.parent_scope.module = anonymous_module;
|
||||||
} else {
|
} else {
|
||||||
self.ribs[ValueNS].push(Rib::new(NormalRibKind));
|
self.ribs[ValueNS].push(Rib::new(RibKind::Normal));
|
||||||
}
|
}
|
||||||
|
|
||||||
let prev = self.diagnostic_metadata.current_block_could_be_bare_struct_literal.take();
|
let prev = self.diagnostic_metadata.current_block_could_be_bare_struct_literal.take();
|
||||||
|
@ -3901,8 +3899,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
&& let ItemKind::MacroDef(..) = item.kind {
|
&& let ItemKind::MacroDef(..) = item.kind {
|
||||||
num_macro_definition_ribs += 1;
|
num_macro_definition_ribs += 1;
|
||||||
let res = self.r.local_def_id(item.id).to_def_id();
|
let res = self.r.local_def_id(item.id).to_def_id();
|
||||||
self.ribs[ValueNS].push(Rib::new(MacroDefinition(res)));
|
self.ribs[ValueNS].push(Rib::new(RibKind::MacroDefinition(res)));
|
||||||
self.label_ribs.push(Rib::new(MacroDefinition(res)));
|
self.label_ribs.push(Rib::new(RibKind::MacroDefinition(res)));
|
||||||
}
|
}
|
||||||
|
|
||||||
self.visit_stmt(stmt);
|
self.visit_stmt(stmt);
|
||||||
|
@ -3989,7 +3987,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
ExprKind::If(ref cond, ref then, ref opt_else) => {
|
ExprKind::If(ref cond, ref then, ref opt_else) => {
|
||||||
self.with_rib(ValueNS, NormalRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||||
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
||||||
this.visit_expr(cond);
|
this.visit_expr(cond);
|
||||||
this.diagnostic_metadata.in_if_condition = old;
|
this.diagnostic_metadata.in_if_condition = old;
|
||||||
|
@ -4006,7 +4004,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
|
|
||||||
ExprKind::While(ref cond, ref block, label) => {
|
ExprKind::While(ref cond, ref block, label) => {
|
||||||
self.with_resolved_label(label, expr.id, |this| {
|
self.with_resolved_label(label, expr.id, |this| {
|
||||||
this.with_rib(ValueNS, NormalRibKind, |this| {
|
this.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||||
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
let old = this.diagnostic_metadata.in_if_condition.replace(cond);
|
||||||
this.visit_expr(cond);
|
this.visit_expr(cond);
|
||||||
this.diagnostic_metadata.in_if_condition = old;
|
this.diagnostic_metadata.in_if_condition = old;
|
||||||
|
@ -4017,7 +4015,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
|
|
||||||
ExprKind::ForLoop(ref pat, ref iter_expr, ref block, label) => {
|
ExprKind::ForLoop(ref pat, ref iter_expr, ref block, label) => {
|
||||||
self.visit_expr(iter_expr);
|
self.visit_expr(iter_expr);
|
||||||
self.with_rib(ValueNS, NormalRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||||
this.resolve_pattern_top(pat, PatternSource::For);
|
this.resolve_pattern_top(pat, PatternSource::For);
|
||||||
this.resolve_labeled_block(label, expr.id, block);
|
this.resolve_labeled_block(label, expr.id, block);
|
||||||
});
|
});
|
||||||
|
@ -4073,8 +4071,8 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
ref body,
|
ref body,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
self.with_rib(ValueNS, NormalRibKind, |this| {
|
self.with_rib(ValueNS, RibKind::Normal, |this| {
|
||||||
this.with_label_rib(ClosureOrAsyncRibKind, |this| {
|
this.with_label_rib(RibKind::ClosureOrAsync, |this| {
|
||||||
// Resolve arguments:
|
// Resolve arguments:
|
||||||
this.resolve_params(&fn_decl.inputs);
|
this.resolve_params(&fn_decl.inputs);
|
||||||
// No need to resolve return type --
|
// No need to resolve return type --
|
||||||
|
@ -4098,7 +4096,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}) => {
|
}) => {
|
||||||
self.with_generic_param_rib(
|
self.with_generic_param_rib(
|
||||||
&generic_params,
|
&generic_params,
|
||||||
NormalRibKind,
|
RibKind::Normal,
|
||||||
LifetimeRibKind::Generics {
|
LifetimeRibKind::Generics {
|
||||||
binder: expr.id,
|
binder: expr.id,
|
||||||
kind: LifetimeBinderKind::Closure,
|
kind: LifetimeBinderKind::Closure,
|
||||||
|
@ -4109,7 +4107,7 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
ExprKind::Closure(..) => visit::walk_expr(self, expr),
|
ExprKind::Closure(..) => visit::walk_expr(self, expr),
|
||||||
ExprKind::Async(..) => {
|
ExprKind::Async(..) => {
|
||||||
self.with_label_rib(ClosureOrAsyncRibKind, |this| visit::walk_expr(this, expr));
|
self.with_label_rib(RibKind::ClosureOrAsync, |this| visit::walk_expr(this, expr));
|
||||||
}
|
}
|
||||||
ExprKind::Repeat(ref elem, ref ct) => {
|
ExprKind::Repeat(ref elem, ref ct) => {
|
||||||
self.visit_expr(elem);
|
self.visit_expr(elem);
|
||||||
|
|
|
@ -605,7 +605,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to find in last block rib
|
// Try to find in last block rib
|
||||||
if let Some(rib) = &self.last_block_rib && let RibKind::NormalRibKind = rib.kind {
|
if let Some(rib) = &self.last_block_rib && let RibKind::Normal = rib.kind {
|
||||||
for (ident, &res) in &rib.bindings {
|
for (ident, &res) in &rib.bindings {
|
||||||
if let Res::Local(_) = res && path.len() == 1 &&
|
if let Res::Local(_) = res && path.len() == 1 &&
|
||||||
ident.span.eq_ctxt(path[0].ident.span) &&
|
ident.span.eq_ctxt(path[0].ident.span) &&
|
||||||
|
@ -1690,7 +1690,7 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Items in scope
|
// Items in scope
|
||||||
if let RibKind::ModuleRibKind(module) = rib.kind {
|
if let RibKind::Module(module) = rib.kind {
|
||||||
// Items from this module
|
// Items from this module
|
||||||
self.r.add_module_candidates(module, &mut names, &filter_fn, Some(ctxt));
|
self.r.add_module_candidates(module, &mut names, &filter_fn, Some(ctxt));
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
// detected then -Zincremental-verify-ich will trigger an assertion.
|
// detected then -Zincremental-verify-ich will trigger an assertion.
|
||||||
|
|
||||||
// ignore-wasm32-bare compiled with panic=abort by default
|
// ignore-wasm32-bare compiled with panic=abort by default
|
||||||
|
// needs-unwind
|
||||||
// revisions:cfail1 cfail2
|
// revisions:cfail1 cfail2
|
||||||
// compile-flags: -Z query-dep-graph -Cpanic=unwind
|
// compile-flags: -Z query-dep-graph -Cpanic=unwind
|
||||||
// build-pass (FIXME(62277): could be check-pass?)
|
// build-pass (FIXME(62277): could be check-pass?)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
// revisions: rfail1 rfail2
|
// revisions: rfail1 rfail2
|
||||||
// failure-status: 101
|
// failure-status: 101
|
||||||
// error-pattern: not implemented
|
// error-pattern: not implemented
|
||||||
|
// needs-unwind -Cpanic=abort causes abort instead of exit(101)
|
||||||
|
|
||||||
pub trait Interner {
|
pub trait Interner {
|
||||||
type InternedVariableKinds;
|
type InternedVariableKinds;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all: archive
|
all: archive
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all: $(call NATIVE_STATICLIB,add)
|
all: $(call NATIVE_STATICLIB,add)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# needs-unwind -Cpanic=abort gives different MIR output
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all: foo
|
all: foo
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all: foo
|
all: foo
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
# ignore-i686-pc-windows-gnu
|
# ignore-i686-pc-windows-gnu
|
||||||
|
# needs-unwind
|
||||||
|
|
||||||
# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder
|
# This test doesn't work on 32-bit MinGW as cdylib has its own copy of unwinder
|
||||||
# so cross-DLL unwinding does not work.
|
# so cross-DLL unwinding does not work.
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
# Test expected libtest's JSON output
|
# Test expected libtest's JSON output
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
all:
|
all:
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
include ../tools.mk
|
include ../tools.mk
|
||||||
|
|
||||||
# ignore-cross-compile
|
# ignore-cross-compile
|
||||||
|
# needs-unwind #[bench] and -Zpanic-abort-tests can't be combined
|
||||||
|
|
||||||
all:
|
all:
|
||||||
# Smoke-test that `#[bench]` isn't entirely broken.
|
# Smoke-test that `#[bench]` isn't entirely broken.
|
||||||
|
|
|
@ -2,28 +2,30 @@
|
||||||
#![feature(generic_const_exprs)]
|
#![feature(generic_const_exprs)]
|
||||||
#![allow(incomplete_features, unused_parens, unused_braces)]
|
#![allow(incomplete_features, unused_parens, unused_braces)]
|
||||||
|
|
||||||
fn zero_init<const N: usize>() -> Substs1<{ (N) }>
|
fn zero_init<const N: usize>() -> Substs1<{{ N }}>
|
||||||
where
|
where
|
||||||
[u8; { (N) }]: ,
|
[u8; {{ N }}]: ,
|
||||||
{
|
{
|
||||||
Substs1([0; { (N) }])
|
Substs1([0; {{ N }}])
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Substs1<const N: usize>([u8; { (N) }])
|
struct Substs1<const N: usize>([u8; {{ N }}])
|
||||||
where
|
where
|
||||||
[(); { (N) }]: ;
|
[(); {{ N }}]: ;
|
||||||
|
|
||||||
fn substs2<const M: usize>() -> Substs1<{ (M) }> {
|
fn substs2<const M: usize>() -> Substs1<{{ M }}> {
|
||||||
zero_init::<{ (M) }>()
|
zero_init::<{{ M }}>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn substs3<const L: usize>() -> Substs1<{ (L) }> {
|
fn substs3<const L: usize>() -> Substs1<{{ L }}> {
|
||||||
substs2::<{ (L) }>()
|
substs2::<{{ L }}>()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(substs3::<2>().0, [0; 2]);
|
assert_eq!(substs3::<2>().0, [0; 2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test that the implicit ``{ (L) }`` bound on ``substs3`` satisfies the
|
// Test that the implicit ``{{ L }}`` bound on ``substs3`` satisfies the
|
||||||
// ``{ (N) }`` bound on ``Substs1``
|
// ``{{ N }}`` bound on ``Substs1``
|
||||||
|
// FIXME(generic_const_exprs): come up with a less brittle test for this using assoc consts
|
||||||
|
// once normalization is implemented for them.
|
||||||
|
|
|
@ -11,15 +11,9 @@ impl Drop for UnconstDrop {
|
||||||
fn drop(&mut self) {}
|
fn drop(&mut self) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NonDrop;
|
|
||||||
|
|
||||||
impl !Drop for NonDrop {}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
const {
|
const {
|
||||||
f(UnconstDrop);
|
f(UnconstDrop);
|
||||||
//~^ ERROR can't drop
|
//~^ ERROR can't drop
|
||||||
f(NonDrop);
|
|
||||||
//~^ ERROR can't drop
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
error[E0277]: can't drop `UnconstDrop` in const contexts
|
error[E0277]: can't drop `UnconstDrop` in const contexts
|
||||||
--> $DIR/const-block-const-bound.rs:20:9
|
--> $DIR/const-block-const-bound.rs:16:9
|
||||||
|
|
|
|
||||||
LL | f(UnconstDrop);
|
LL | f(UnconstDrop);
|
||||||
| ^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `UnconstDrop`
|
| ^^^^^^^^^^^^^^ the trait `~const Destruct` is not implemented for `UnconstDrop`
|
||||||
|
@ -12,20 +12,6 @@ LL | &f(UnconstDrop);
|
||||||
LL | &mut f(UnconstDrop);
|
LL | &mut f(UnconstDrop);
|
||||||
| ++++
|
| ++++
|
||||||
|
|
||||||
error[E0277]: can't drop `NonDrop` in const contexts
|
error: aborting due to previous error
|
||||||
--> $DIR/const-block-const-bound.rs:22:9
|
|
||||||
|
|
|
||||||
LL | f(NonDrop);
|
|
||||||
| ^^^^^^^^^^ the trait `~const Destruct` is not implemented for `NonDrop`
|
|
||||||
|
|
|
||||||
= note: the trait bound `NonDrop: ~const Destruct` is not satisfied
|
|
||||||
help: consider borrowing here
|
|
||||||
|
|
|
||||||
LL | &f(NonDrop);
|
|
||||||
| +
|
|
||||||
LL | &mut f(NonDrop);
|
|
||||||
| ++++
|
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
|
||||||
|
|
||||||
For more information about this error, try `rustc --explain E0277`.
|
For more information about this error, try `rustc --explain E0277`.
|
||||||
|
|
7
tests/ui/dropck/negative.rs
Normal file
7
tests/ui/dropck/negative.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
#![feature(negative_impls)]
|
||||||
|
|
||||||
|
struct NonDrop;
|
||||||
|
impl !Drop for NonDrop {}
|
||||||
|
//~^ ERROR negative `Drop` impls are not supported
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/dropck/negative.stderr
Normal file
8
tests/ui/dropck/negative.stderr
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: negative `Drop` impls are not supported
|
||||||
|
--> $DIR/negative.rs:4:1
|
||||||
|
|
|
||||||
|
LL | impl !Drop for NonDrop {}
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
10
tests/ui/dropck/reservation.rs
Normal file
10
tests/ui/dropck/reservation.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#![feature(rustc_attrs)]
|
||||||
|
|
||||||
|
struct ReservedDrop;
|
||||||
|
#[rustc_reservation_impl = "message"]
|
||||||
|
impl Drop for ReservedDrop {
|
||||||
|
//~^ ERROR reservation `Drop` impls are not supported
|
||||||
|
fn drop(&mut self) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
8
tests/ui/dropck/reservation.stderr
Normal file
8
tests/ui/dropck/reservation.stderr
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
error: reservation `Drop` impls are not supported
|
||||||
|
--> $DIR/reservation.rs:5:1
|
||||||
|
|
|
||||||
|
LL | impl Drop for ReservedDrop {
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
|
@ -5,10 +5,10 @@
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
|
||||||
pub trait Foo {
|
pub trait Foo {
|
||||||
fn bar() -> impl Deref<Target = impl Sized>;
|
fn bar(self) -> impl Deref<Target = impl Sized>;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Foreign;
|
pub struct Foreign;
|
||||||
impl Foo for Foreign {
|
impl Foo for Foreign {
|
||||||
fn bar() -> &'static () { &() }
|
fn bar(self) -> &'static () { &() }
|
||||||
}
|
}
|
||||||
|
|
8
tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
Normal file
8
tests/ui/impl-trait/in-trait/foreign-dyn-error.rs
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
// aux-build: rpitit.rs
|
||||||
|
|
||||||
|
extern crate rpitit;
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _: &dyn rpitit::Foo = todo!();
|
||||||
|
//~^ ERROR the trait `Foo` cannot be made into an object
|
||||||
|
}
|
15
tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
Normal file
15
tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
error[E0038]: the trait `Foo` cannot be made into an object
|
||||||
|
--> $DIR/foreign-dyn-error.rs:6:12
|
||||||
|
|
|
||||||
|
LL | let _: &dyn rpitit::Foo = todo!();
|
||||||
|
| ^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
|
||||||
|
|
|
||||||
|
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
|
||||||
|
--> $DIR/auxiliary/rpitit.rs:8:21
|
||||||
|
|
|
||||||
|
LL | fn bar(self) -> impl Deref<Target = impl Sized>;
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because method `bar` references an `impl Trait` type in its return type
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0038`.
|
|
@ -5,17 +5,18 @@
|
||||||
|
|
||||||
extern crate rpitit;
|
extern crate rpitit;
|
||||||
|
|
||||||
|
use rpitit::{Foo, Foreign};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
// Implement an RPITIT from another crate.
|
// Implement an RPITIT from another crate.
|
||||||
struct Local;
|
struct Local;
|
||||||
impl rpitit::Foo for Local {
|
impl Foo for Local {
|
||||||
fn bar() -> Arc<String> { Arc::new(String::new()) }
|
fn bar(self) -> Arc<String> { Arc::new(String::new()) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// Witness an RPITIT from another crate.
|
// Witness an RPITIT from another crate.
|
||||||
let &() = <rpitit::Foreign as rpitit::Foo>::bar();
|
let &() = Foreign.bar();
|
||||||
|
|
||||||
let x: Arc<String> = <Local as rpitit::Foo>::bar();
|
let x: Arc<String> = Local.bar();
|
||||||
}
|
}
|
||||||
|
|
17
tests/ui/self/self-ctor-inner-const.rs
Normal file
17
tests/ui/self/self-ctor-inner-const.rs
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
// Verify that we ban usage of `Self` as constructor from inner items.
|
||||||
|
|
||||||
|
struct S0<T>(T);
|
||||||
|
|
||||||
|
impl<T> S0<T> {
|
||||||
|
fn foo() {
|
||||||
|
const C: S0<u8> = Self(0);
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
fn bar() -> Self {
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
Self(0)
|
||||||
|
//~^ ERROR can't use generic parameters from outer function
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
33
tests/ui/self/self-ctor-inner-const.stderr
Normal file
33
tests/ui/self/self-ctor-inner-const.stderr
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:7:27
|
||||||
|
|
|
||||||
|
LL | const C: S0<u8> = Self(0);
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| can't use `Self` here
|
||||||
|
|
||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:9:21
|
||||||
|
|
|
||||||
|
LL | impl<T> S0<T> {
|
||||||
|
| ---- `Self` type implicitly declared here, by this `impl`
|
||||||
|
...
|
||||||
|
LL | fn bar() -> Self {
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| use a type here instead
|
||||||
|
|
||||||
|
error[E0401]: can't use generic parameters from outer function
|
||||||
|
--> $DIR/self-ctor-inner-const.rs:11:13
|
||||||
|
|
|
||||||
|
LL | Self(0)
|
||||||
|
| ^^^^
|
||||||
|
| |
|
||||||
|
| use of generic parameter from outer function
|
||||||
|
| can't use `Self` here
|
||||||
|
|
||||||
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
For more information about this error, try `rustc --explain E0401`.
|
|
@ -3,6 +3,7 @@
|
||||||
// check-run-results
|
// check-run-results
|
||||||
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
|
||||||
// ignore-emscripten no threads support
|
// ignore-emscripten no threads support
|
||||||
|
// needs-unwind
|
||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue