mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #108357 - matthiaskrgr:rollup-ceo3q2s, r=matthiaskrgr
Rollup of 6 pull requests Successful merges: - #107736 ( Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref #66893) ) - #108176 (Don't delay `ReError` bug during lexical region resolve) - #108315 (Lint dead code in closures and generators) - #108342 (apply query response: actually define opaque types) - #108344 (Fix test filename for #105700) - #108353 (resolve: Remove `ImportResolver`) Failed merges: - #107911 (Add check for invalid #[macro_export] arguments) r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
da439d9874
@ -393,6 +393,7 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
/// will instantiate fresh inference variables for each canonical
|
||||
/// variable instead. Therefore, the result of this method must be
|
||||
/// properly unified
|
||||
#[instrument(level = "debug", skip(self, cause, param_env))]
|
||||
fn query_response_substitution_guess<R>(
|
||||
&self,
|
||||
cause: &ObligationCause<'tcx>,
|
||||
@ -403,11 +404,6 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
where
|
||||
R: Debug + TypeFoldable<TyCtxt<'tcx>>,
|
||||
{
|
||||
debug!(
|
||||
"query_response_substitution_guess(original_values={:#?}, query_response={:#?})",
|
||||
original_values, query_response,
|
||||
);
|
||||
|
||||
// For each new universe created in the query result that did
|
||||
// not appear in the original query, create a local
|
||||
// superuniverse.
|
||||
@ -502,7 +498,9 @@ impl<'tcx> InferCtxt<'tcx> {
|
||||
for &(a, b) in &query_response.value.opaque_types {
|
||||
let a = substitute_value(self.tcx, &result_subst, a);
|
||||
let b = substitute_value(self.tcx, &result_subst, b);
|
||||
obligations.extend(self.at(cause, param_env).eq(a, b)?.obligations);
|
||||
debug!(?a, ?b, "constrain opaque type");
|
||||
obligations
|
||||
.extend(self.at(cause, param_env).define_opaque_types(true).eq(a, b)?.obligations);
|
||||
}
|
||||
|
||||
Ok(InferOk { value: result_subst, obligations })
|
||||
|
@ -1046,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
|
||||
ty::ReVar(rid) => match self.values[rid] {
|
||||
VarValue::Empty(_) => r,
|
||||
VarValue::Value(r) => r,
|
||||
VarValue::ErrorValue => tcx.mk_re_error_misc(),
|
||||
VarValue::ErrorValue => tcx.lifetimes.re_static,
|
||||
},
|
||||
_ => r,
|
||||
};
|
||||
|
@ -395,6 +395,9 @@ impl<'tcx> Visitor<'tcx> for MarkSymbolVisitor<'tcx> {
|
||||
self.mark_as_used_if_union(*adt, fields);
|
||||
}
|
||||
}
|
||||
hir::ExprKind::Closure(cls) => {
|
||||
self.insert_def_id(cls.def_id.to_def_id());
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ use rustc_span::{BytePos, Span, SyntaxContext};
|
||||
use thin_vec::ThinVec;
|
||||
|
||||
use crate::errors as errs;
|
||||
use crate::imports::{Import, ImportKind, ImportResolver};
|
||||
use crate::imports::{Import, ImportKind};
|
||||
use crate::late::{PatternSource, Rib};
|
||||
use crate::path_names_to_string;
|
||||
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind, BindingError, Finalize};
|
||||
@ -1888,15 +1888,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
(format!("use of undeclared crate or module `{}`", ident), suggestion)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
/// Adds suggestions for a path that cannot be resolved.
|
||||
pub(crate) fn make_path_suggestion(
|
||||
&mut self,
|
||||
span: Span,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Option<(Vec<Segment>, Option<String>)> {
|
||||
debug!("make_path_suggestion: span={:?} path={:?}", span, path);
|
||||
|
||||
@ -1931,11 +1929,11 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
fn make_missing_self_suggestion(
|
||||
&mut self,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Option<(Vec<Segment>, Option<String>)> {
|
||||
// Replace first ident with `self` and check if that is valid.
|
||||
path[0].ident.name = kw::SelfLower;
|
||||
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
|
||||
let result = self.maybe_resolve_path(&path, None, parent_scope);
|
||||
debug!("make_missing_self_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
|
||||
}
|
||||
@ -1950,11 +1948,11 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
fn make_missing_crate_suggestion(
|
||||
&mut self,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Option<(Vec<Segment>, Option<String>)> {
|
||||
// Replace first ident with `crate` and check if that is valid.
|
||||
path[0].ident.name = kw::Crate;
|
||||
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
|
||||
let result = self.maybe_resolve_path(&path, None, parent_scope);
|
||||
debug!("make_missing_crate_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result {
|
||||
Some((
|
||||
@ -1981,11 +1979,11 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
fn make_missing_super_suggestion(
|
||||
&mut self,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Option<(Vec<Segment>, Option<String>)> {
|
||||
// Replace first ident with `crate` and check if that is valid.
|
||||
path[0].ident.name = kw::Super;
|
||||
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
|
||||
let result = self.maybe_resolve_path(&path, None, parent_scope);
|
||||
debug!("make_missing_super_suggestion: path={:?} result={:?}", path, result);
|
||||
if let PathResult::Module(..) = result { Some((path, None)) } else { None }
|
||||
}
|
||||
@ -2003,7 +2001,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
fn make_external_crate_suggestion(
|
||||
&mut self,
|
||||
mut path: Vec<Segment>,
|
||||
parent_scope: &ParentScope<'b>,
|
||||
parent_scope: &ParentScope<'a>,
|
||||
) -> Option<(Vec<Segment>, Option<String>)> {
|
||||
if path[1].ident.span.is_rust_2015() {
|
||||
return None;
|
||||
@ -2013,13 +2011,13 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// 1) some consistent ordering for emitted diagnostics, and
|
||||
// 2) `std` suggestions before `core` suggestions.
|
||||
let mut extern_crate_names =
|
||||
self.r.extern_prelude.iter().map(|(ident, _)| ident.name).collect::<Vec<_>>();
|
||||
self.extern_prelude.iter().map(|(ident, _)| ident.name).collect::<Vec<_>>();
|
||||
extern_crate_names.sort_by(|a, b| b.as_str().partial_cmp(a.as_str()).unwrap());
|
||||
|
||||
for name in extern_crate_names.into_iter() {
|
||||
// Replace first ident with a crate name and check if that is valid.
|
||||
path[0].ident.name = name;
|
||||
let result = self.r.maybe_resolve_path(&path, None, parent_scope);
|
||||
let result = self.maybe_resolve_path(&path, None, parent_scope);
|
||||
debug!(
|
||||
"make_external_crate_suggestion: name={:?} path={:?} result={:?}",
|
||||
name, path, result
|
||||
@ -2046,8 +2044,8 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
/// ```
|
||||
pub(crate) fn check_for_module_export_macro(
|
||||
&mut self,
|
||||
import: &'b Import<'b>,
|
||||
module: ModuleOrUniformRoot<'b>,
|
||||
import: &'a Import<'a>,
|
||||
module: ModuleOrUniformRoot<'a>,
|
||||
ident: Ident,
|
||||
) -> Option<(Option<Suggestion>, Option<String>)> {
|
||||
let ModuleOrUniformRoot::Module(mut crate_module) = module else {
|
||||
@ -2064,8 +2062,8 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let resolutions = self.r.resolutions(crate_module).borrow();
|
||||
let resolution = resolutions.get(&self.r.new_key(ident, MacroNS))?;
|
||||
let resolutions = self.resolutions(crate_module).borrow();
|
||||
let resolution = resolutions.get(&self.new_key(ident, MacroNS))?;
|
||||
let binding = resolution.borrow().binding()?;
|
||||
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() {
|
||||
let module_name = crate_module.kind.name().unwrap();
|
||||
@ -2086,7 +2084,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// ie. `use a::b::{c, d, e};`
|
||||
// ^^^
|
||||
let (found_closing_brace, binding_span) = find_span_of_binding_until_next_binding(
|
||||
self.r.tcx.sess,
|
||||
self.tcx.sess,
|
||||
import.span,
|
||||
import.use_span,
|
||||
);
|
||||
@ -2105,7 +2103,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// ie. `use a::b::{c, d};`
|
||||
// ^^^
|
||||
if let Some(previous_span) =
|
||||
extend_span_to_previous_binding(self.r.tcx.sess, binding_span)
|
||||
extend_span_to_previous_binding(self.tcx.sess, binding_span)
|
||||
{
|
||||
debug!("check_for_module_export_macro: previous_span={:?}", previous_span);
|
||||
removal_span = removal_span.with_lo(previous_span.lo());
|
||||
@ -2123,7 +2121,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// or `use a::{b, c, d}};`
|
||||
// ^^^^^^^^^^^
|
||||
let (has_nested, after_crate_name) = find_span_immediately_after_crate_name(
|
||||
self.r.tcx.sess,
|
||||
self.tcx.sess,
|
||||
module_name,
|
||||
import.use_span,
|
||||
);
|
||||
@ -2132,7 +2130,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
has_nested, after_crate_name
|
||||
);
|
||||
|
||||
let source_map = self.r.tcx.sess.source_map();
|
||||
let source_map = self.tcx.sess.source_map();
|
||||
|
||||
// Make sure this is actually crate-relative.
|
||||
let is_definitely_crate = import
|
||||
|
@ -210,6 +210,17 @@ impl<'a> NameResolution<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved
|
||||
/// import errors within the same use tree into a single diagnostic.
|
||||
#[derive(Debug, Clone)]
|
||||
struct UnresolvedImportError {
|
||||
span: Span,
|
||||
label: Option<String>,
|
||||
note: Option<String>,
|
||||
suggestion: Option<Suggestion>,
|
||||
candidates: Option<Vec<ImportSuggestion>>,
|
||||
}
|
||||
|
||||
// Reexports of the form `pub use foo as bar;` where `foo` is `extern crate foo;`
|
||||
// are permitted for backward-compatibility under a deprecation lint.
|
||||
fn pub_use_of_private_extern_crate_hack(import: &Import<'_>, binding: &NameBinding<'_>) -> bool {
|
||||
@ -392,24 +403,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An error that may be transformed into a diagnostic later. Used to combine multiple unresolved
|
||||
/// import errors within the same use tree into a single diagnostic.
|
||||
#[derive(Debug, Clone)]
|
||||
struct UnresolvedImportError {
|
||||
span: Span,
|
||||
label: Option<String>,
|
||||
note: Option<String>,
|
||||
suggestion: Option<Suggestion>,
|
||||
candidates: Option<Vec<ImportSuggestion>>,
|
||||
}
|
||||
|
||||
pub(crate) struct ImportResolver<'a, 'b, 'tcx> {
|
||||
pub r: &'a mut Resolver<'b, 'tcx>,
|
||||
}
|
||||
|
||||
impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// Import resolution
|
||||
//
|
||||
// This is a fixed-point algorithm. We resolve imports until our efforts
|
||||
@ -421,28 +415,28 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
/// Resolves all imports for the crate. This method performs the fixed-
|
||||
/// point iteration.
|
||||
pub(crate) fn resolve_imports(&mut self) {
|
||||
let mut prev_num_indeterminates = self.r.indeterminate_imports.len() + 1;
|
||||
while self.r.indeterminate_imports.len() < prev_num_indeterminates {
|
||||
prev_num_indeterminates = self.r.indeterminate_imports.len();
|
||||
for import in mem::take(&mut self.r.indeterminate_imports) {
|
||||
let mut prev_num_indeterminates = self.indeterminate_imports.len() + 1;
|
||||
while self.indeterminate_imports.len() < prev_num_indeterminates {
|
||||
prev_num_indeterminates = self.indeterminate_imports.len();
|
||||
for import in mem::take(&mut self.indeterminate_imports) {
|
||||
match self.resolve_import(&import) {
|
||||
true => self.r.determined_imports.push(import),
|
||||
false => self.r.indeterminate_imports.push(import),
|
||||
true => self.determined_imports.push(import),
|
||||
false => self.indeterminate_imports.push(import),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn finalize_imports(&mut self) {
|
||||
for module in self.r.arenas.local_modules().iter() {
|
||||
for module in self.arenas.local_modules().iter() {
|
||||
self.finalize_resolutions_in(module);
|
||||
}
|
||||
|
||||
let mut seen_spans = FxHashSet::default();
|
||||
let mut errors = vec![];
|
||||
let mut prev_root_id: NodeId = NodeId::from_u32(0);
|
||||
let determined_imports = mem::take(&mut self.r.determined_imports);
|
||||
let indeterminate_imports = mem::take(&mut self.r.indeterminate_imports);
|
||||
let determined_imports = mem::take(&mut self.determined_imports);
|
||||
let indeterminate_imports = mem::take(&mut self.indeterminate_imports);
|
||||
|
||||
for (is_indeterminate, import) in determined_imports
|
||||
.into_iter()
|
||||
@ -453,7 +447,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
// If this import is unresolved then create a dummy import
|
||||
// resolution for it so that later resolve stages won't complain.
|
||||
self.r.import_dummy_binding(import);
|
||||
self.import_dummy_binding(import);
|
||||
|
||||
if let Some(err) = unresolved_import_error {
|
||||
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
|
||||
@ -526,7 +520,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
.collect::<Vec<_>>();
|
||||
let msg = format!("unresolved import{} {}", pluralize!(paths.len()), paths.join(", "),);
|
||||
|
||||
let mut diag = struct_span_err!(self.r.tcx.sess, span, E0432, "{}", &msg);
|
||||
let mut diag = struct_span_err!(self.tcx.sess, span, E0432, "{}", &msg);
|
||||
|
||||
if let Some((_, UnresolvedImportError { note: Some(note), .. })) = errors.iter().last() {
|
||||
diag.note(note);
|
||||
@ -548,7 +542,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
if let Some(candidates) = &err.candidates {
|
||||
match &import.kind {
|
||||
ImportKind::Single { nested: false, source, target, .. } => import_candidates(
|
||||
self.r.tcx,
|
||||
self.tcx,
|
||||
&mut diag,
|
||||
Some(err.span),
|
||||
&candidates,
|
||||
@ -560,7 +554,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
),
|
||||
ImportKind::Single { nested: true, source, target, .. } => {
|
||||
import_candidates(
|
||||
self.r.tcx,
|
||||
self.tcx,
|
||||
&mut diag,
|
||||
None,
|
||||
&candidates,
|
||||
@ -581,7 +575,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
/// Attempts to resolve the given import, returning true if its resolution is determined.
|
||||
/// If successful, the resolved bindings are written into the module.
|
||||
fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
|
||||
fn resolve_import(&mut self, import: &'a Import<'a>) -> bool {
|
||||
debug!(
|
||||
"(resolving import for module) resolving import `{}::...` in `{}`",
|
||||
Segment::names_to_string(&import.module_path),
|
||||
@ -594,8 +588,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// For better failure detection, pretend that the import will
|
||||
// not define any names while resolving its module path.
|
||||
let orig_vis = import.vis.take();
|
||||
let path_res =
|
||||
self.r.maybe_resolve_path(&import.module_path, None, &import.parent_scope);
|
||||
let path_res = self.maybe_resolve_path(&import.module_path, None, &import.parent_scope);
|
||||
import.vis.set(orig_vis);
|
||||
|
||||
match path_res {
|
||||
@ -623,7 +616,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
};
|
||||
|
||||
let mut indeterminate = false;
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if !type_ns_only || ns == TypeNS {
|
||||
if let Err(Undetermined) = source_bindings[ns].get() {
|
||||
// For better failure detection, pretend that the import will
|
||||
@ -676,15 +669,15 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
///
|
||||
/// Optionally returns an unresolved import error. This error is buffered and used to
|
||||
/// consolidate multiple unresolved import errors into a single diagnostic.
|
||||
fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImportError> {
|
||||
fn finalize_import(&mut self, import: &'a Import<'a>) -> Option<UnresolvedImportError> {
|
||||
let orig_vis = import.vis.take();
|
||||
let ignore_binding = match &import.kind {
|
||||
ImportKind::Single { target_bindings, .. } => target_bindings[TypeNS].get(),
|
||||
_ => None,
|
||||
};
|
||||
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
|
||||
let prev_ambiguity_errors_len = self.ambiguity_errors.len();
|
||||
let finalize = Finalize::with_root_span(import.root_id, import.span, import.root_span);
|
||||
let path_res = self.r.resolve_path(
|
||||
let path_res = self.resolve_path(
|
||||
&import.module_path,
|
||||
None,
|
||||
&import.parent_scope,
|
||||
@ -692,7 +685,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
ignore_binding,
|
||||
);
|
||||
|
||||
let no_ambiguity = self.r.ambiguity_errors.len() == prev_ambiguity_errors_len;
|
||||
let no_ambiguity = self.ambiguity_errors.len() == prev_ambiguity_errors_len;
|
||||
import.vis.set(orig_vis);
|
||||
let module = match path_res {
|
||||
PathResult::Module(module) => {
|
||||
@ -701,10 +694,10 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
if !ModuleOrUniformRoot::same_def(module, initial_module) && no_ambiguity {
|
||||
span_bug!(import.span, "inconsistent resolution for an import");
|
||||
}
|
||||
} else if self.r.privacy_errors.is_empty() {
|
||||
} else if self.privacy_errors.is_empty() {
|
||||
let msg = "cannot determine resolution for the import";
|
||||
let msg_note = "import resolution is stuck, try simplifying other imports";
|
||||
self.r.tcx.sess.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||
self.tcx.sess.struct_span_err(import.span, msg).note(msg_note).emit();
|
||||
}
|
||||
|
||||
module
|
||||
@ -712,8 +705,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
PathResult::Failed { is_error_from_last_segment: false, span, label, suggestion } => {
|
||||
if no_ambiguity {
|
||||
assert!(import.imported_module.get().is_none());
|
||||
self.r
|
||||
.report_error(span, ResolutionError::FailedToResolve { label, suggestion });
|
||||
self.report_error(span, ResolutionError::FailedToResolve { label, suggestion });
|
||||
}
|
||||
return None;
|
||||
}
|
||||
@ -775,7 +767,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||
let mut full_path = import.module_path.clone();
|
||||
full_path.push(Segment::from_ident(Ident::empty()));
|
||||
self.r.lint_if_path_starts_with_module(Some(finalize), &full_path, None);
|
||||
self.lint_if_path_starts_with_module(Some(finalize), &full_path, None);
|
||||
}
|
||||
|
||||
if let ModuleOrUniformRoot::Module(module) = module {
|
||||
@ -794,10 +786,10 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
}
|
||||
if !is_prelude
|
||||
&& let Some(max_vis) = max_vis.get()
|
||||
&& !max_vis.is_at_least(import.expect_vis(), &*self.r)
|
||||
&& !max_vis.is_at_least(import.expect_vis(), &*self)
|
||||
{
|
||||
let msg = "glob import doesn't reexport anything because no candidate is public enough";
|
||||
self.r.lint_buffer.buffer_lint(UNUSED_IMPORTS, id, import.span, msg);
|
||||
self.lint_buffer.buffer_lint(UNUSED_IMPORTS, id, import.span, msg);
|
||||
}
|
||||
return None;
|
||||
}
|
||||
@ -805,7 +797,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
};
|
||||
|
||||
let mut all_ns_err = true;
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if !type_ns_only || ns == TypeNS {
|
||||
let orig_vis = import.vis.take();
|
||||
let binding = this.resolve_ident_in_module(
|
||||
@ -874,7 +866,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
if all_ns_err {
|
||||
let mut all_ns_failed = true;
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if !type_ns_only || ns == TypeNS {
|
||||
let binding = this.resolve_ident_in_module(
|
||||
module,
|
||||
@ -892,9 +884,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
return if all_ns_failed {
|
||||
let resolutions = match module {
|
||||
ModuleOrUniformRoot::Module(module) => {
|
||||
Some(self.r.resolutions(module).borrow())
|
||||
}
|
||||
ModuleOrUniformRoot::Module(module) => Some(self.resolutions(module).borrow()),
|
||||
_ => None,
|
||||
};
|
||||
let resolutions = resolutions.as_ref().into_iter().flat_map(|r| r.iter());
|
||||
@ -963,7 +953,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
};
|
||||
|
||||
let parent_suggestion =
|
||||
self.r.lookup_import_candidates(ident, TypeNS, &import.parent_scope, |_| true);
|
||||
self.lookup_import_candidates(ident, TypeNS, &import.parent_scope, |_| true);
|
||||
|
||||
Some(UnresolvedImportError {
|
||||
span: import.span,
|
||||
@ -985,7 +975,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
let mut reexport_error = None;
|
||||
let mut any_successful_reexport = false;
|
||||
let mut crate_private_reexport = false;
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
if !binding.vis.is_at_least(import.expect_vis(), &*this) {
|
||||
reexport_error = Some((ns, binding));
|
||||
@ -1010,7 +1000,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
`pub`",
|
||||
ident
|
||||
);
|
||||
self.r.lint_buffer.buffer_lint(
|
||||
self.lint_buffer.buffer_lint(
|
||||
PUB_USE_OF_PRIVATE_EXTERN_CRATE,
|
||||
import_id,
|
||||
import.span,
|
||||
@ -1033,17 +1023,17 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
format!("re-export of private `{}`", ident)
|
||||
};
|
||||
|
||||
struct_span_err!(self.r.tcx.sess, import.span, E0365, "{}", error_msg)
|
||||
struct_span_err!(self.tcx.sess, import.span, E0365, "{}", error_msg)
|
||||
.span_label(import.span, label_msg)
|
||||
.note(&format!("consider declaring type or module `{}` with `pub`", ident))
|
||||
.emit();
|
||||
} else {
|
||||
let mut err =
|
||||
struct_span_err!(self.r.tcx.sess, import.span, E0364, "{error_msg}");
|
||||
struct_span_err!(self.tcx.sess, import.span, E0364, "{error_msg}");
|
||||
match binding.kind {
|
||||
NameBindingKind::Res(Res::Def(DefKind::Macro(_), def_id))
|
||||
// exclude decl_macro
|
||||
if self.r.get_macro_by_def_id(def_id).macro_rules =>
|
||||
if self.get_macro_by_def_id(def_id).macro_rules =>
|
||||
{
|
||||
err.span_help(
|
||||
binding.span,
|
||||
@ -1069,7 +1059,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// 2 segments, so the `resolve_path` above won't trigger it.
|
||||
let mut full_path = import.module_path.clone();
|
||||
full_path.push(Segment::from_ident(ident));
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
this.lint_if_path_starts_with_module(Some(finalize), &full_path, Some(binding));
|
||||
}
|
||||
@ -1079,7 +1069,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// Record what this import resolves to for later uses in documentation,
|
||||
// this may resolve to either a value or a type, but for documentation
|
||||
// purposes it's good enough to just favor one over the other.
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
this.import_res_map.entry(import_id).or_default()[ns] = Some(binding.res());
|
||||
}
|
||||
@ -1094,9 +1084,9 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
fn check_for_redundant_imports(
|
||||
&mut self,
|
||||
ident: Ident,
|
||||
import: &'b Import<'b>,
|
||||
source_bindings: &PerNS<Cell<Result<&'b NameBinding<'b>, Determinacy>>>,
|
||||
target_bindings: &PerNS<Cell<Option<&'b NameBinding<'b>>>>,
|
||||
import: &'a Import<'a>,
|
||||
source_bindings: &PerNS<Cell<Result<&'a NameBinding<'a>, Determinacy>>>,
|
||||
target_bindings: &PerNS<Cell<Option<&'a NameBinding<'a>>>>,
|
||||
target: Ident,
|
||||
) {
|
||||
// This function is only called for single imports.
|
||||
@ -1117,7 +1107,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
|
||||
let mut redundant_span = PerNS { value_ns: None, type_ns: None, macro_ns: None };
|
||||
|
||||
self.r.per_ns(|this, ns| {
|
||||
self.per_ns(|this, ns| {
|
||||
if let Ok(binding) = source_bindings[ns].get() {
|
||||
if binding.res() == Res::Err {
|
||||
return;
|
||||
@ -1147,7 +1137,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
let mut redundant_spans: Vec<_> = redundant_span.present_items().collect();
|
||||
redundant_spans.sort();
|
||||
redundant_spans.dedup();
|
||||
self.r.lint_buffer.buffer_lint_with_diagnostic(
|
||||
self.lint_buffer.buffer_lint_with_diagnostic(
|
||||
UNUSED_IMPORTS,
|
||||
id,
|
||||
import.span,
|
||||
@ -1157,22 +1147,22 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
fn resolve_glob_import(&mut self, import: &'b Import<'b>) {
|
||||
fn resolve_glob_import(&mut self, import: &'a Import<'a>) {
|
||||
// This function is only called for glob imports.
|
||||
let ImportKind::Glob { id, is_prelude, .. } = import.kind else { unreachable!() };
|
||||
|
||||
let ModuleOrUniformRoot::Module(module) = import.imported_module.get().unwrap() else {
|
||||
self.r.tcx.sess.span_err(import.span, "cannot glob-import all possible crates");
|
||||
self.tcx.sess.span_err(import.span, "cannot glob-import all possible crates");
|
||||
return;
|
||||
};
|
||||
|
||||
if module.is_trait() {
|
||||
self.r.tcx.sess.span_err(import.span, "items in traits are not importable");
|
||||
self.tcx.sess.span_err(import.span, "items in traits are not importable");
|
||||
return;
|
||||
} else if ptr::eq(module, import.parent_scope.module) {
|
||||
return;
|
||||
} else if is_prelude {
|
||||
self.r.prelude = Some(module);
|
||||
self.prelude = Some(module);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1182,7 +1172,6 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
// Ensure that `resolutions` isn't borrowed during `try_define`,
|
||||
// since it might get updated via a glob cycle.
|
||||
let bindings = self
|
||||
.r
|
||||
.resolutions(module)
|
||||
.borrow()
|
||||
.iter()
|
||||
@ -1192,30 +1181,30 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
.collect::<Vec<_>>();
|
||||
for (mut key, binding) in bindings {
|
||||
let scope = match key.ident.span.reverse_glob_adjust(module.expansion, import.span) {
|
||||
Some(Some(def)) => self.r.expn_def_scope(def),
|
||||
Some(Some(def)) => self.expn_def_scope(def),
|
||||
Some(None) => import.parent_scope.module,
|
||||
None => continue,
|
||||
};
|
||||
if self.r.is_accessible_from(binding.vis, scope) {
|
||||
let imported_binding = self.r.import(binding, import);
|
||||
let _ = self.r.try_define(import.parent_scope.module, key, imported_binding);
|
||||
if self.is_accessible_from(binding.vis, scope) {
|
||||
let imported_binding = self.import(binding, import);
|
||||
let _ = self.try_define(import.parent_scope.module, key, imported_binding);
|
||||
}
|
||||
}
|
||||
|
||||
// Record the destination of this import
|
||||
self.r.record_partial_res(id, PartialRes::new(module.res().unwrap()));
|
||||
self.record_partial_res(id, PartialRes::new(module.res().unwrap()));
|
||||
}
|
||||
|
||||
// Miscellaneous post-processing, including recording re-exports,
|
||||
// reporting conflicts, and reporting unresolved imports.
|
||||
fn finalize_resolutions_in(&mut self, module: Module<'b>) {
|
||||
fn finalize_resolutions_in(&mut self, module: Module<'a>) {
|
||||
// Since import resolution is finished, globs will not define any more names.
|
||||
*module.globs.borrow_mut() = Vec::new();
|
||||
|
||||
if let Some(def_id) = module.opt_def_id() {
|
||||
let mut reexports = Vec::new();
|
||||
|
||||
module.for_each_child(self.r, |this, ident, _, binding| {
|
||||
module.for_each_child(self, |this, ident, _, binding| {
|
||||
if let Some(res) = this.is_reexport(binding) {
|
||||
reexports.push(ModChild {
|
||||
ident,
|
||||
@ -1230,7 +1219,7 @@ impl<'a, 'b, 'tcx> ImportResolver<'a, 'b, 'tcx> {
|
||||
if !reexports.is_empty() {
|
||||
// Call to `expect_local` should be fine because current
|
||||
// code is only called for local modules.
|
||||
self.r.reexport_map.insert(def_id.expect_local(), reexports);
|
||||
self.reexport_map.insert(def_id.expect_local(), reexports);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ use std::collections::BTreeSet;
|
||||
use std::{fmt, ptr};
|
||||
|
||||
use diagnostics::{ImportSuggestion, LabelSuggestion, Suggestion};
|
||||
use imports::{Import, ImportKind, ImportResolver, NameResolution};
|
||||
use imports::{Import, ImportKind, NameResolution};
|
||||
use late::{HasGenericParams, PathSource, PatternSource};
|
||||
use macros::{MacroRulesBinding, MacroRulesScope, MacroRulesScopeRef};
|
||||
|
||||
@ -1491,9 +1491,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
|
||||
/// Entry point to crate resolution.
|
||||
pub fn resolve_crate(&mut self, krate: &Crate) {
|
||||
self.tcx.sess.time("resolve_crate", || {
|
||||
self.tcx
|
||||
.sess
|
||||
.time("finalize_imports", || ImportResolver { r: self }.finalize_imports());
|
||||
self.tcx.sess.time("finalize_imports", || self.finalize_imports());
|
||||
self.tcx.sess.time("compute_effective_visibilities", || {
|
||||
EffectiveVisibilitiesVisitor::compute_effective_visibilities(self, krate)
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
//! A bunch of methods and structures more or less related to resolving macros and
|
||||
//! interface provided by `Resolver` to macro expander.
|
||||
|
||||
use crate::imports::ImportResolver;
|
||||
use crate::Namespace::*;
|
||||
use crate::{BuiltinMacroState, Determinacy};
|
||||
use crate::{DeriveData, Finalize, ParentScope, ResolutionError, Resolver, ScopeSet};
|
||||
@ -233,7 +232,7 @@ impl<'a, 'tcx> ResolverExpand for Resolver<'a, 'tcx> {
|
||||
}
|
||||
|
||||
fn resolve_imports(&mut self) {
|
||||
ImportResolver { r: self }.resolve_imports()
|
||||
self.resolve_imports()
|
||||
}
|
||||
|
||||
fn resolve_macro_invocation(
|
||||
|
@ -922,13 +922,13 @@ impl AtomicBool {
|
||||
///
|
||||
/// let mut atomic = AtomicBool::new(true);
|
||||
/// unsafe {
|
||||
/// my_atomic_op(atomic.as_mut_ptr());
|
||||
/// my_atomic_op(atomic.as_ptr());
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")]
|
||||
pub const fn as_mut_ptr(&self) -> *mut bool {
|
||||
pub const fn as_ptr(&self) -> *mut bool {
|
||||
self.v.get().cast()
|
||||
}
|
||||
|
||||
@ -1814,12 +1814,12 @@ impl<T> AtomicPtr<T> {
|
||||
///
|
||||
/// // SAFETY: Safe as long as `my_atomic_op` is atomic.
|
||||
/// unsafe {
|
||||
/// my_atomic_op(atomic.as_mut_ptr());
|
||||
/// my_atomic_op(atomic.as_ptr());
|
||||
/// }
|
||||
/// ```
|
||||
#[inline]
|
||||
#[unstable(feature = "atomic_mut_ptr", reason = "recently added", issue = "66893")]
|
||||
pub const fn as_mut_ptr(&self) -> *mut *mut T {
|
||||
pub const fn as_ptr(&self) -> *mut *mut T {
|
||||
self.p.get()
|
||||
}
|
||||
}
|
||||
@ -2719,7 +2719,7 @@ macro_rules! atomic_int {
|
||||
///
|
||||
/// // SAFETY: Safe as long as `my_atomic_op` is atomic.
|
||||
/// unsafe {
|
||||
/// my_atomic_op(atomic.as_mut_ptr());
|
||||
/// my_atomic_op(atomic.as_ptr());
|
||||
/// }
|
||||
/// # }
|
||||
/// ```
|
||||
@ -2727,7 +2727,7 @@ macro_rules! atomic_int {
|
||||
#[unstable(feature = "atomic_mut_ptr",
|
||||
reason = "recently added",
|
||||
issue = "66893")]
|
||||
pub const fn as_mut_ptr(&self) -> *mut $int_type {
|
||||
pub const fn as_ptr(&self) -> *mut $int_type {
|
||||
self.v.get()
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ impl Parker {
|
||||
if state == PARKED {
|
||||
// Loop to guard against spurious wakeups.
|
||||
while state == PARKED {
|
||||
park(self.state.as_mut_ptr().addr());
|
||||
park(self.state.as_ptr().addr());
|
||||
state = self.state.load(Acquire);
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ impl Parker {
|
||||
|
||||
let state = self.state.fetch_sub(1, Acquire).wrapping_sub(1);
|
||||
if state == PARKED {
|
||||
park_timeout(dur, self.state.as_mut_ptr().addr());
|
||||
park_timeout(dur, self.state.as_ptr().addr());
|
||||
// Swap to ensure that we observe all state changes with acquire
|
||||
// ordering, even if the state has been changed after the timeout
|
||||
// occured.
|
||||
@ -99,7 +99,7 @@ impl Parker {
|
||||
// and terminated before this call is made. This call then returns an
|
||||
// error or wakes up an unrelated thread. The platform API and
|
||||
// environment does allow this, however.
|
||||
unpark(tid, self.state.as_mut_ptr().addr());
|
||||
unpark(tid, self.state.as_ptr().addr());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
16
tests/ui/lint/dead-code/in-closure.rs
Normal file
16
tests/ui/lint/dead-code/in-closure.rs
Normal file
@ -0,0 +1,16 @@
|
||||
// edition: 2021
|
||||
|
||||
#![deny(dead_code)]
|
||||
|
||||
pub fn foo() {
|
||||
let closure = || {
|
||||
fn a() {} //~ ERROR function `a` is never used
|
||||
};
|
||||
closure()
|
||||
}
|
||||
|
||||
pub async fn async_foo() {
|
||||
const A: usize = 1; //~ ERROR constant `A` is never used
|
||||
}
|
||||
|
||||
fn main() {}
|
20
tests/ui/lint/dead-code/in-closure.stderr
Normal file
20
tests/ui/lint/dead-code/in-closure.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: function `a` is never used
|
||||
--> $DIR/in-closure.rs:7:12
|
||||
|
|
||||
LL | fn a() {}
|
||||
| ^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/in-closure.rs:3:9
|
||||
|
|
||||
LL | #![deny(dead_code)]
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: constant `A` is never used
|
||||
--> $DIR/in-closure.rs:13:11
|
||||
|
|
||||
LL | const A: usize = 1;
|
||||
| ^
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
@ -1,10 +1,10 @@
|
||||
error: recursion limit reached while expanding `#[invalid_attribute]`
|
||||
--> $DIR/issue_21102.rs:6:1
|
||||
--> $DIR/issue-105700.rs:6:1
|
||||
|
|
||||
LL | #![invalid_attribute]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`issue_21102`)
|
||||
= help: consider increasing the recursion limit by adding a `#![recursion_limit = "8"]` attribute to your crate (`issue_105700`)
|
||||
|
||||
error: aborting due to previous error
|
||||
|
22
tests/ui/regions/resolve-re-error-ice.rs
Normal file
22
tests/ui/regions/resolve-re-error-ice.rs
Normal file
@ -0,0 +1,22 @@
|
||||
// check-pass
|
||||
|
||||
// Allow this for now, can remove this UI test when this becomes a hard error.
|
||||
#![allow(implied_bounds_entailment)]
|
||||
|
||||
use std::collections::hash_map::{Keys, HashMap};
|
||||
use std::marker::PhantomData;
|
||||
|
||||
trait MapAssertion<'a, K, V, R> {
|
||||
fn key_set(&self) -> Subject<Keys<K, V>, (), R>;
|
||||
}
|
||||
|
||||
struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>);
|
||||
|
||||
impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap<K, V>, (), R>
|
||||
{
|
||||
fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
15
tests/ui/regions/resolve-re-error-ice.stderr
Normal file
15
tests/ui/regions/resolve-re-error-ice.stderr
Normal file
@ -0,0 +1,15 @@
|
||||
Future incompatibility report: Future breakage diagnostic:
|
||||
warning: impl method assumes more implied bounds than the corresponding trait method
|
||||
--> $DIR/resolve-re-error-ice.rs:17:16
|
||||
|
|
||||
LL | fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> {
|
||||
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `Subject<'_, std::collections::hash_map::Keys<'_, K, V>, (), R>`
|
||||
|
|
||||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
|
||||
= note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572>
|
||||
note: the lint level is defined here
|
||||
--> $DIR/resolve-re-error-ice.rs:4:10
|
||||
|
|
||||
LL | #![allow(implied_bounds_entailment)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
Loading…
Reference in New Issue
Block a user