Skip to content

Commit

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

Rollup of 6 pull requests

Successful merges:

 - rust-lang#115796 (Generate aggregate constants in DataflowConstProp.)
 - rust-lang#116859 (Make `ty::print::Printer` take `&mut self` instead of `self`)
 - rust-lang#117046 (return unfixed len if pat has reported error)
 - rust-lang#117070 (rustdoc: wrap Type with Box instead of Generics)
 - rust-lang#117074 (Remove smir from triage and add me to stablemir)
 - rust-lang#117086 (Update .mailmap to promote my livename)

r? `@ghost`
`@rustbot` modify labels: rollup
  • Loading branch information
bors committed Oct 23, 2023
2 parents 1322f92 + 542397d commit 2dd0f1a
Show file tree
Hide file tree
Showing 49 changed files with 1,476 additions and 783 deletions.
2 changes: 2 additions & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ Alexis Beingessner <a.beingessner@gmail.com>
Alfie John <alfie@alfie.wtf> Alfie John <alfiej@fastmail.fm>
Alona Enraght-Moony <code@alona.page> <nixon.emoony@gmail.com>
Alona Enraght-Moony <code@alona.page> <nixon@caminus.local>
Amanda Stjerna <mail@amandastjerna.se> <albin.stjerna@gmail.com>
Amanda Stjerna <mail@amandastjerna.se> <amanda.stjerna@it.uu.se>
Amos Onn <amosonn@gmail.com>
Ana-Maria Mihalache <mihalacheana.maria@yahoo.com>
Anatoly Ikorsky <aikorsky@gmail.com>
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
}
}

ty.print(printer).unwrap().into_buffer()
ty.print(&mut printer).unwrap();
printer.into_buffer()
}

/// Returns the name of the provided `Ty` (that must be a reference)'s region with a
Expand All @@ -492,7 +493,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
bug!("ty for annotation of borrow region is not a reference");
};

region.print(printer).unwrap().into_buffer()
region.print(&mut printer).unwrap();
printer.into_buffer()
}
}

Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/interpret/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
/// Helper function for printing a scalar to a FmtPrinter
fn p<'a, 'tcx, Prov: Provenance>(
cx: FmtPrinter<'a, 'tcx>,
cx: &mut FmtPrinter<'a, 'tcx>,
s: Scalar<Prov>,
ty: Ty<'tcx>,
) -> Result<FmtPrinter<'a, 'tcx>, std::fmt::Error> {
) -> Result<(), std::fmt::Error> {
match s {
Scalar::Int(int) => cx.pretty_print_const_scalar_int(int, ty, true),
Scalar::Ptr(ptr, _sz) => {
Expand All @@ -125,8 +125,9 @@ impl<Prov: Provenance> std::fmt::Display for ImmTy<'_, Prov> {
match self.imm {
Immediate::Scalar(s) => {
if let Some(ty) = tcx.lift(self.layout.ty) {
let cx = FmtPrinter::new(tcx, Namespace::ValueNS);
f.write_str(&p(cx, s, ty)?.into_buffer())?;
let s =
FmtPrinter::print_string(tcx, Namespace::ValueNS, |cx| p(cx, s, ty))?;
f.write_str(&s)?;
return Ok(());
}
write!(f, "{:x}: {}", s, self.layout.ty)
Expand Down
76 changes: 39 additions & 37 deletions compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
self.tcx
}

fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> {
Ok(self)
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
Ok(())
}

fn print_type(mut self, ty: Ty<'tcx>) -> Result<Self, PrintError> {
fn print_type(&mut self, ty: Ty<'tcx>) -> Result<(), PrintError> {
match *ty.kind() {
// Types without identity.
ty::Bool
Expand All @@ -43,7 +43,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
// Placeholders (all printed as `_` to uniformize them).
ty::Param(_) | ty::Bound(..) | ty::Placeholder(_) | ty::Infer(_) | ty::Error(_) => {
write!(self, "_")?;
Ok(self)
Ok(())
}

// Types with identity (print the module path).
Expand All @@ -60,74 +60,74 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
}
}

fn print_const(self, ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
fn print_const(&mut self, ct: ty::Const<'tcx>) -> Result<(), PrintError> {
self.pretty_print_const(ct, false)
}

fn print_dyn_existential(
self,
&mut self,
predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
self.pretty_print_dyn_existential(predicates)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
self.path.push_str(self.tcx.crate_name(cnum).as_str());
Ok(self)
Ok(())
}

fn path_qualified(
self,
&mut self,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
self.pretty_path_qualified(self_ty, trait_ref)
}

fn path_append_impl(
self,
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
_disambiguated_data: &DisambiguatedDefPathData,
self_ty: Ty<'tcx>,
trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
self.pretty_path_append_impl(
|mut cx| {
cx = print_prefix(cx)?;
|cx| {
print_prefix(cx)?;

cx.path.push_str("::");

Ok(cx)
Ok(())
},
self_ty,
trait_ref,
)
}

fn path_append(
mut self,
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self, PrintError> {
self = print_prefix(self)?;
) -> Result<(), PrintError> {
print_prefix(self)?;

write!(self.path, "::{}", disambiguated_data.data).unwrap();

Ok(self)
Ok(())
}

fn path_generic_args(
mut self,
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
args: &[GenericArg<'tcx>],
) -> Result<Self, PrintError> {
self = print_prefix(self)?;
) -> Result<(), PrintError> {
print_prefix(self)?;
let args =
args.iter().cloned().filter(|arg| !matches!(arg.unpack(), GenericArgKind::Lifetime(_)));
if args.clone().next().is_some() {
self.generic_delimiters(|cx| cx.comma_sep(args))
} else {
Ok(self)
Ok(())
}
}
}
Expand All @@ -136,31 +136,31 @@ impl<'tcx> PrettyPrinter<'tcx> for AbsolutePathPrinter<'tcx> {
fn should_print_region(&self, _region: ty::Region<'_>) -> bool {
false
}
fn comma_sep<T>(mut self, mut elems: impl Iterator<Item = T>) -> Result<Self, PrintError>
fn comma_sep<T>(&mut self, mut elems: impl Iterator<Item = T>) -> Result<(), PrintError>
where
T: Print<'tcx, Self>,
{
if let Some(first) = elems.next() {
self = first.print(self)?;
first.print(self)?;
for elem in elems {
self.path.push_str(", ");
self = elem.print(self)?;
elem.print(self)?;
}
}
Ok(self)
Ok(())
}

fn generic_delimiters(
mut self,
f: impl FnOnce(Self) -> Result<Self, PrintError>,
) -> Result<Self, PrintError> {
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), PrintError>,
) -> Result<(), PrintError> {
write!(self, "<")?;

self = f(self)?;
f(self)?;

write!(self, ">")?;

Ok(self)
Ok(())
}

fn should_print_verbose(&self) -> bool {
Expand All @@ -177,5 +177,7 @@ impl Write for AbsolutePathPrinter<'_> {
}

pub fn type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> String {
AbsolutePathPrinter { tcx, path: String::new() }.print_type(ty).unwrap().path
let mut printer = AbsolutePathPrinter { tcx, path: String::new() };
printer.print_type(ty).unwrap();
printer.path
}
15 changes: 14 additions & 1 deletion compiler/rustc_hir_typeck/src/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use rustc_hir::pat_util::EnumerateAndAdjustIterator;
use rustc_hir::{HirId, Pat, PatKind};
use rustc_infer::infer;
use rustc_infer::infer::type_variable::{TypeVariableOrigin, TypeVariableOriginKind};
use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::ty::{self, Adt, BindingMode, Ty, TypeVisitableExt};
use rustc_session::lint::builtin::NON_EXHAUSTIVE_OMITTED_PATTERNS;
use rustc_span::edit_distance::find_best_match_for_name;
Expand Down Expand Up @@ -2164,7 +2165,19 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
len: ty::Const<'tcx>,
min_len: u64,
) -> (Option<Ty<'tcx>>, Ty<'tcx>) {
let guar = if let Some(len) = len.try_eval_target_usize(self.tcx, self.param_env) {
let len = match len.eval(self.tcx, self.param_env, None) {
Ok(val) => val
.try_to_scalar()
.and_then(|scalar| scalar.try_to_int().ok())
.and_then(|int| int.try_to_target_usize(self.tcx).ok()),
Err(ErrorHandled::Reported(..)) => {
let guar = self.error_scrutinee_unfixed_length(span);
return (Some(Ty::new_error(self.tcx, guar)), arr_ty);
}
Err(ErrorHandled::TooGeneric(..)) => None,
};

let guar = if let Some(len) = len {
// Now we know the length...
if slice.is_none() {
// ...and since there is no variable-length pattern,
Expand Down
47 changes: 23 additions & 24 deletions compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -588,60 +588,60 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
self.tcx
}

fn print_region(self, _region: ty::Region<'_>) -> Result<Self, PrintError> {
fn print_region(&mut self, _region: ty::Region<'_>) -> Result<(), PrintError> {
Err(fmt::Error)
}

fn print_type(self, _ty: Ty<'tcx>) -> Result<Self, PrintError> {
fn print_type(&mut self, _ty: Ty<'tcx>) -> Result<(), PrintError> {
Err(fmt::Error)
}

fn print_dyn_existential(
self,
&mut self,
_predicates: &'tcx ty::List<ty::PolyExistentialPredicate<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
Err(fmt::Error)
}

fn print_const(self, _ct: ty::Const<'tcx>) -> Result<Self, PrintError> {
fn print_const(&mut self, _ct: ty::Const<'tcx>) -> Result<(), PrintError> {
Err(fmt::Error)
}

fn path_crate(mut self, cnum: CrateNum) -> Result<Self, PrintError> {
fn path_crate(&mut self, cnum: CrateNum) -> Result<(), PrintError> {
self.segments = vec![self.tcx.crate_name(cnum).to_string()];
Ok(self)
Ok(())
}
fn path_qualified(
self,
&mut self,
_self_ty: Ty<'tcx>,
_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
Err(fmt::Error)
}

fn path_append_impl(
self,
_print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
_print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
_disambiguated_data: &DisambiguatedDefPathData,
_self_ty: Ty<'tcx>,
_trait_ref: Option<ty::TraitRef<'tcx>>,
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
Err(fmt::Error)
}
fn path_append(
mut self,
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
disambiguated_data: &DisambiguatedDefPathData,
) -> Result<Self, PrintError> {
self = print_prefix(self)?;
) -> Result<(), PrintError> {
print_prefix(self)?;
self.segments.push(disambiguated_data.to_string());
Ok(self)
Ok(())
}
fn path_generic_args(
self,
print_prefix: impl FnOnce(Self) -> Result<Self, PrintError>,
&mut self,
print_prefix: impl FnOnce(&mut Self) -> Result<(), PrintError>,
_args: &[GenericArg<'tcx>],
) -> Result<Self, PrintError> {
) -> Result<(), PrintError> {
print_prefix(self)
}
}
Expand All @@ -652,9 +652,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
// let _ = [{struct Foo; Foo}, {struct Foo; Foo}];
if did1.krate != did2.krate {
let abs_path = |def_id| {
AbsolutePathPrinter { tcx: self.tcx, segments: vec![] }
.print_def_path(def_id, &[])
.map(|p| p.segments)
let mut printer = AbsolutePathPrinter { tcx: self.tcx, segments: vec![] };
printer.print_def_path(def_id, &[]).map(|_| printer.segments)
};

// We compare strings because DefPath can be different
Expand Down Expand Up @@ -1071,7 +1070,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {

let get_lifetimes = |sig| {
use rustc_hir::def::Namespace;
let (_, sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
let (sig, reg) = ty::print::FmtPrinter::new(self.tcx, Namespace::TypeNS)
.name_all_regions(sig)
.unwrap();
let lts: Vec<String> = reg.into_values().map(|kind| kind.to_string()).collect();
Expand Down
Loading

0 comments on commit 2dd0f1a

Please sign in to comment.