Skip to content

Commit

Permalink
Auto merge of rust-lang#108357 - matthiaskrgr:rollup-ceo3q2s, r=matth…
Browse files Browse the repository at this point in the history
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#107736 ( Rename atomic 'as_mut_ptr' to 'as_ptr' to match Cell (ref rust-lang#66893) )
 - rust-lang#108176 (Don't delay `ReError` bug during lexical region resolve)
 - rust-lang#108315 (Lint dead code in closures and generators)
 - rust-lang#108342 (apply query response: actually define opaque types)
 - rust-lang#108344 (Fix test filename for rust-lang#105700)
 - rust-lang#108353 (resolve: Remove `ImportResolver`)

Failed merges:

 - rust-lang#107911 (Add check for invalid #[macro_export] arguments)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Feb 22, 2023
2 parents fdbc432 + 9f5c401 commit da439d9
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 121 deletions.
10 changes: 4 additions & 6 deletions compiler/rustc_infer/src/infer/canonical/query_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
Expand All @@ -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.
Expand Down Expand Up @@ -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 })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_passes/src/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
_ => (),
}

Expand Down
40 changes: 19 additions & 21 deletions compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 }
}
Expand All @@ -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((
Expand All @@ -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 }
}
Expand All @@ -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;
Expand All @@ -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
Expand All @@ -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 {
Expand All @@ -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();
Expand All @@ -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,
);
Expand All @@ -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());
Expand All @@ -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,
);
Expand All @@ -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
Expand Down
Loading

0 comments on commit da439d9

Please sign in to comment.