Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #118277

Merged
merged 22 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8cc7073
Replace `option.map(cond) == Some(true)` with `option.is_some_and(cond)`
dtolnay Nov 24, 2023
7a6dce3
Request that rust-analyzer changes are sent upstream first if possible
dtolnay Nov 24, 2023
1b7b954
rustdoc-search: avoid infinite where clause unbox
notriddle Nov 24, 2023
798d2cb
Move EagerResolution to rustc_infer::infer::resolve
spastorino Nov 24, 2023
6713f29
We should call eq instead of sup as we're relating Ty directly and no…
spastorino Nov 21, 2023
6d881a9
add change information for PR#117813
onur-ozkan Nov 23, 2023
38aba2c
use the change-id from source instead of the one from config.tom
onur-ozkan Nov 23, 2023
576a17e
move CONFIG_CHANGE_HISTORY to its own module
onur-ozkan Nov 23, 2023
5ad84ed
Break down `rustc_smir/mod.rs` file
celinval Nov 24, 2023
d7c7236
Move the compiler interface defs to its own module
celinval Nov 24, 2023
f8c2478
Reorder imports and remove re-export
celinval Nov 24, 2023
b601b40
Separate Nan/Inf floats with _
compiler-errors Nov 24, 2023
60817e6
Fix smir's `Ty::Ref` pretty printing
celinval Nov 25, 2023
fb2c498
Rollup merge of #118220 - onur-ozkan:followups, r=Mark-Simulacrum
fmease Nov 25, 2023
0304aac
Rollup merge of #118251 - notriddle:notriddle/less-recursion, r=Guill…
fmease Nov 25, 2023
8e606a6
Rollup merge of #118253 - dtolnay:issomeand, r=compiler-errors
fmease Nov 25, 2023
969a773
Rollup merge of #118255 - dtolnay:mentionsrustanalyzer, r=Mark-Simula…
fmease Nov 25, 2023
7c2244a
Rollup merge of #118259 - spastorino:move-eager-resolver-to-infer, r=…
fmease Nov 25, 2023
23461fd
Rollup merge of #118262 - spastorino:relate-iats-using-eq, r=compiler…
fmease Nov 25, 2023
3f513bd
Rollup merge of #118266 - celinval:smir-break-files, r=compiler-errors
fmease Nov 25, 2023
a663bb9
Rollup merge of #118271 - compiler-errors:float, r=RalfJung
fmease Nov 25, 2023
20d243e
Rollup merge of #118274 - celinval:smir-fix-pretty, r=ouz-a
fmease Nov 25, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/scripts/rustc-clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
args.push(codegen_backend_arg);
}
if !passed_args.iter().any(|arg| {
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
}) {
args.push(OsString::from("--sysroot"));
args.push(OsString::from(sysroot.to_str().unwrap()));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/scripts/rustdoc-clif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
args.push(codegen_backend_arg);
}
if !passed_args.iter().any(|arg| {
arg == "--sysroot" || arg.to_str().map(|s| s.starts_with("--sysroot=")) == Some(true)
arg == "--sysroot" || arg.to_str().is_some_and(|s| s.starts_with("--sysroot="))
}) {
args.push(OsString::from("--sysroot"));
args.push(OsString::from(sysroot.to_str().unwrap()));
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_expand/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ pub(crate) fn matches_codepattern(a: &str, b: &str) -> bool {

/// Advances the given peekable `Iterator` until it reaches a non-whitespace character.
fn scan_for_non_ws_or_end<I: Iterator<Item = char>>(iter: &mut Peekable<I>) {
while iter.peek().copied().map(rustc_lexer::is_whitespace) == Some(true) {
while iter.peek().copied().is_some_and(rustc_lexer::is_whitespace) {
iter.next();
}
}
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_hir_analysis/src/astconv/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1674,10 +1674,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
let impl_ty = ocx.normalize(&cause, param_env, impl_ty);

// Check that the self types can be related.
// FIXME(inherent_associated_types): Should we use `eq` here? Method probing uses
// `sup` for this situtation, too. What for? To constrain inference variables?
if ocx.sup(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err()
{
if ocx.eq(&ObligationCause::dummy(), param_env, impl_ty, self_ty).is_err() {
return false;
}

Expand Down
10 changes: 6 additions & 4 deletions compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2293,12 +2293,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let clone_trait =
self.tcx.require_lang_item(LangItem::Clone, Some(segment.ident.span));
if args.is_empty()
&& self.typeck_results.borrow().type_dependent_def_id(expr.hir_id).map(
|did| {
&& self
.typeck_results
.borrow()
.type_dependent_def_id(expr.hir_id)
.is_some_and(|did| {
let ai = self.tcx.associated_item(did);
ai.trait_container(self.tcx) == Some(clone_trait)
},
) == Some(true)
})
&& segment.ident.name == sym::clone
{
// If this expression had a clone call when suggesting borrowing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
&& self
.tcx()
.opt_associated_item(scope_def_id.to_def_id())
.map(|i| i.fn_has_self_parameter)
== Some(true)
.is_some_and(|i| i.fn_has_self_parameter)
}
}
82 changes: 82 additions & 0 deletions compiler/rustc_infer/src/infer/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,85 @@ impl<'a, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for FullTypeResolver<'a, 'tcx> {
}
}
}

///////////////////////////////////////////////////////////////////////////
// EAGER RESOLUTION

/// Resolves ty, region, and const vars to their inferred values or their root vars.
pub struct EagerResolver<'a, 'tcx> {
infcx: &'a InferCtxt<'tcx>,
}

impl<'a, 'tcx> EagerResolver<'a, 'tcx> {
pub fn new(infcx: &'a InferCtxt<'tcx>) -> Self {
EagerResolver { infcx }
}
}

impl<'tcx> TypeFolder<TyCtxt<'tcx>> for EagerResolver<'_, 'tcx> {
fn interner(&self) -> TyCtxt<'tcx> {
self.infcx.tcx
}

fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
match *t.kind() {
ty::Infer(ty::TyVar(vid)) => match self.infcx.probe_ty_var(vid) {
Ok(t) => t.fold_with(self),
Err(_) => Ty::new_var(self.infcx.tcx, self.infcx.root_var(vid)),
},
ty::Infer(ty::IntVar(vid)) => self.infcx.opportunistic_resolve_int_var(vid),
ty::Infer(ty::FloatVar(vid)) => self.infcx.opportunistic_resolve_float_var(vid),
_ => {
if t.has_infer() {
t.super_fold_with(self)
} else {
t
}
}
}
}

fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
match *r {
ty::ReVar(vid) => self
.infcx
.inner
.borrow_mut()
.unwrap_region_constraints()
.opportunistic_resolve_var(self.infcx.tcx, vid),
_ => r,
}
}

fn fold_const(&mut self, c: ty::Const<'tcx>) -> ty::Const<'tcx> {
match c.kind() {
ty::ConstKind::Infer(ty::InferConst::Var(vid)) => {
// FIXME: we need to fold the ty too, I think.
match self.infcx.probe_const_var(vid) {
Ok(c) => c.fold_with(self),
Err(_) => {
ty::Const::new_var(self.infcx.tcx, self.infcx.root_const_var(vid), c.ty())
}
}
}
ty::ConstKind::Infer(ty::InferConst::EffectVar(vid)) => {
debug_assert_eq!(c.ty(), self.infcx.tcx.types.bool);
match self.infcx.probe_effect_var(vid) {
Some(c) => c.as_const(self.infcx.tcx),
None => ty::Const::new_infer(
self.infcx.tcx,
ty::InferConst::EffectVar(self.infcx.root_effect_var(vid)),
self.infcx.tcx.types.bool,
),
}
}
_ => {
if c.has_infer() {
c.super_fold_with(self)
} else {
c
}
}
}
}
}
16 changes: 6 additions & 10 deletions compiler/rustc_lint/src/non_fmt_panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,17 +154,13 @@ fn check_panic<'tcx>(cx: &LateContext<'tcx>, f: &'tcx hir::Expr<'tcx>, arg: &'tc

let infcx = cx.tcx.infer_ctxt().build();
let suggest_display = is_str
|| cx
.tcx
.get_diagnostic_item(sym::Display)
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
== Some(true);
|| cx.tcx.get_diagnostic_item(sym::Display).is_some_and(|t| {
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
});
let suggest_debug = !suggest_display
&& cx
.tcx
.get_diagnostic_item(sym::Debug)
.map(|t| infcx.type_implements_trait(t, [ty], cx.param_env).may_apply())
== Some(true);
&& cx.tcx.get_diagnostic_item(sym::Debug).is_some_and(|t| {
infcx.type_implements_trait(t, [ty], cx.param_env).may_apply()
});

let suggest_panic_any = !is_str && panic == sym::std_panic_macro;

Expand Down
7 changes: 5 additions & 2 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::ty::{
};
use crate::ty::{GenericArg, GenericArgKind};
use rustc_apfloat::ieee::{Double, Single};
use rustc_apfloat::Float;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
use rustc_data_structures::sso::SsoHashSet;
use rustc_hir as hir;
Expand Down Expand Up @@ -1477,10 +1478,12 @@ pub trait PrettyPrinter<'tcx>: Printer<'tcx> + fmt::Write {
ty::Bool if int == ScalarInt::TRUE => p!("true"),
// Float
ty::Float(ty::FloatTy::F32) => {
p!(write("{}f32", Single::try_from(int).unwrap()))
let val = Single::try_from(int).unwrap();
p!(write("{}{}f32", val, if val.is_finite() { "" } else { "_" }))
}
ty::Float(ty::FloatTy::F64) => {
p!(write("{}f64", Double::try_from(int).unwrap()))
let val = Double::try_from(int).unwrap();
p!(write("{}{}f64", val, if val.is_finite() { "" } else { "_" }))
}
// Int
ty::Uint(_) | ty::Int(_) => {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_smir/src/rustc_internal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! For that, we define APIs that will temporarily be public to 3P that exposes rustc internal APIs
//! until stable MIR is complete.

use crate::rustc_smir::{Stable, Tables, TablesWrapper};
use crate::rustc_smir::{context::TablesWrapper, Stable, Tables};
use rustc_data_structures::fx;
use rustc_data_structures::fx::FxIndexMap;
use rustc_middle::mir::interpret::AllocId;
Expand Down Expand Up @@ -181,7 +181,7 @@ where
instances: IndexMap::default(),
constants: IndexMap::default(),
}));
stable_mir::run(&tables, || init(&tables, f))
stable_mir::compiler_interface::run(&tables, || init(&tables, f))
}

#[macro_export]
Expand Down
Loading
Loading