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 11 pull requests #82530

Merged
merged 25 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
3ed189e
Cleanup `PpMode` and friends
LeSeulArtichaut Feb 18, 2021
dd3772e
A few more code cleanups
LeSeulArtichaut Feb 19, 2021
c9d86aa
Set RUST_BACKTRACE=0 when running `treat-err-as-bug` tests
Aaron1011 Feb 23, 2021
f94c15c
Fix typo in sanitizer flag in unstable book.
frewsxcv Feb 23, 2021
010a6f9
panic_bounds_checks should be panic_bounds_check
jrmuizel Feb 24, 2021
476c6c2
Update outdated comment in unix Command.
ehuss Feb 24, 2021
eefec8a
library: Normalize safety-for-unsafe-block comments
ojeda Feb 24, 2021
5ac6935
Move pick_by_value_method docs above function header
osa1 Feb 24, 2021
9c5f684
Turn Pick field comments into documentation
osa1 Feb 24, 2021
3be69b1
Remove duplicate string
bugadani Feb 24, 2021
d3f75eb
Add test
bugadani Feb 24, 2021
97ab012
Only look for `tidy` when running rustdoc tests
jyn514 Feb 24, 2021
f06896c
fix typo in `pre-commit.sh`
Feb 24, 2021
0ae4bf9
Fix typo in `param_env_reveal_all_normalized` #82510
jyn514 Feb 25, 2021
8c0119d
Rollup merge of #82269 - LeSeulArtichaut:cleanup-ppmode, r=spastorino
Aaron1011 Feb 25, 2021
239e41d
Rollup merge of #82431 - Aaron1011:fix/bug-env, r=jyn514
Aaron1011 Feb 25, 2021
44f85c5
Rollup merge of #82441 - frewsxcv:frewsxcv-docs, r=GuillaumeGomez
Aaron1011 Feb 25, 2021
fe6cbbc
Rollup merge of #82463 - jrmuizel:patch-1, r=steveklabnik
Aaron1011 Feb 25, 2021
503d50b
Rollup merge of #82464 - ehuss:unix-command-comment, r=kennytm
Aaron1011 Feb 25, 2021
befa2df
Rollup merge of #82467 - ojeda:tidy-normalize-safety-comments, r=kennytm
Aaron1011 Feb 25, 2021
9a540cb
Rollup merge of #82468 - osa1:pick_by_value_method_docs, r=petrochenkov
Aaron1011 Feb 25, 2021
8250a25
Rollup merge of #82484 - bugadani:docfix, r=jyn514
Aaron1011 Feb 25, 2021
586ed18
Rollup merge of #82502 - jyn514:tidy, r=petrochenkov
Aaron1011 Feb 25, 2021
4fdca6a
Rollup merge of #82503 - cratelyn:patch-1, r=Mark-Simulacrum
Aaron1011 Feb 25, 2021
42e53ff
Rollup merge of #82510 - jyn514:fix-typo, r=Dylan-DPC
Aaron1011 Feb 25, 2021
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
72 changes: 27 additions & 45 deletions compiler/rustc_driver/src/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use rustc_hir_pretty as pprust_hir;
use rustc_middle::hir::map as hir_map;
use rustc_middle::ty::{self, TyCtxt};
use rustc_mir::util::{write_mir_graphviz, write_mir_pretty};
use rustc_session::config::{Input, PpMode, PpSourceMode};
use rustc_session::config::{Input, PpHirMode, PpMode, PpSourceMode};
use rustc_session::Session;
use rustc_span::symbol::Ident;
use rustc_span::FileName;
Expand Down Expand Up @@ -42,43 +42,41 @@ where
F: FnOnce(&dyn PrinterSupport) -> A,
{
match *ppmode {
PpmNormal | PpmEveryBodyLoops | PpmExpanded => {
Normal | EveryBodyLoops | Expanded => {
let annotation = NoAnn { sess, tcx };
f(&annotation)
}

PpmIdentified | PpmExpandedIdentified => {
Identified | ExpandedIdentified => {
let annotation = IdentifiedAnnotation { sess, tcx };
f(&annotation)
}
PpmExpandedHygiene => {
ExpandedHygiene => {
let annotation = HygieneAnnotation { sess };
f(&annotation)
}
_ => panic!("Should use call_with_pp_support_hir"),
}
}
fn call_with_pp_support_hir<A, F>(ppmode: &PpSourceMode, tcx: TyCtxt<'_>, f: F) -> A
fn call_with_pp_support_hir<A, F>(ppmode: &PpHirMode, tcx: TyCtxt<'_>, f: F) -> A
where
F: FnOnce(&dyn HirPrinterSupport<'_>, &hir::Crate<'_>) -> A,
{
match *ppmode {
PpmNormal => {
PpHirMode::Normal => {
let annotation = NoAnn { sess: tcx.sess, tcx: Some(tcx) };
f(&annotation, tcx.hir().krate())
}

PpmIdentified => {
PpHirMode::Identified => {
let annotation = IdentifiedAnnotation { sess: tcx.sess, tcx: Some(tcx) };
f(&annotation, tcx.hir().krate())
}
PpmTyped => {
PpHirMode::Typed => {
abort_on_err(tcx.analysis(LOCAL_CRATE), tcx.sess);

let annotation = TypedAnnotation { tcx, maybe_typeck_results: Cell::new(None) };
tcx.dep_graph.with_ignore(|| f(&annotation, tcx.hir().krate()))
}
_ => panic!("Should use call_with_pp_support"),
}
}

Expand Down Expand Up @@ -393,16 +391,13 @@ pub fn print_after_parsing(
) {
let (src, src_name) = get_source(input, sess);

let mut out = String::new();

if let PpmSource(s) = ppm {
let out = if let Source(s) = ppm {
// Silently ignores an identified node.
let out = &mut out;
call_with_pp_support(&s, sess, None, move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let parse = &sess.parse_sess;
*out = pprust::print_crate(
pprust::print_crate(
sess.source_map(),
krate,
src_name,
Expand All @@ -413,7 +408,7 @@ pub fn print_after_parsing(
)
})
} else {
unreachable!();
unreachable!()
};

write_or_print(&out, ofile);
Expand All @@ -433,17 +428,14 @@ pub fn print_after_hir_lowering<'tcx>(

let (src, src_name) = get_source(input, tcx.sess);

let mut out = String::new();

match ppm {
PpmSource(s) => {
let out = match ppm {
Source(s) => {
// Silently ignores an identified node.
let out = &mut out;
call_with_pp_support(&s, tcx.sess, Some(tcx), move |annotation| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let parse = &sess.parse_sess;
*out = pprust::print_crate(
pprust::print_crate(
sess.source_map(),
krate,
src_name,
Expand All @@ -455,26 +447,20 @@ pub fn print_after_hir_lowering<'tcx>(
})
}

PpmHir(s) => {
let out = &mut out;
call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing source code {:?}", s);
let sess = annotation.sess();
let sm = sess.source_map();
*out = pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
})
}
Hir(s) => call_with_pp_support_hir(&s, tcx, move |annotation, krate| {
debug!("pretty printing HIR {:?}", s);
let sess = annotation.sess();
let sm = sess.source_map();
pprust_hir::print_crate(sm, krate, src_name, src, annotation.pp_ann())
}),

PpmHirTree(s) => {
let out = &mut out;
call_with_pp_support_hir(&s, tcx, move |_annotation, krate| {
debug!("pretty printing source code {:?}", s);
*out = format!("{:#?}", krate);
});
}
HirTree => call_with_pp_support_hir(&PpHirMode::Normal, tcx, move |_annotation, krate| {
debug!("pretty printing HIR tree");
format!("{:#?}", krate)
}),

_ => unreachable!(),
}
};

write_or_print(&out, ofile);
}
Expand All @@ -493,14 +479,10 @@ fn print_with_analysis(
tcx.analysis(LOCAL_CRATE)?;

match ppm {
PpmMir | PpmMirCFG => match ppm {
PpmMir => write_mir_pretty(tcx, None, &mut out),
PpmMirCFG => write_mir_graphviz(tcx, None, &mut out),
_ => unreachable!(),
},
Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
_ => unreachable!(),
}
.unwrap();

let out = std::str::from_utf8(&out).unwrap();
write_or_print(out, ofile);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_interface/src/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ fn configure_and_expand_inner<'a>(
rustc_builtin_macros::test_harness::inject(&sess, &mut resolver, &mut krate)
});

if let Some(PpMode::PpmSource(PpSourceMode::PpmEveryBodyLoops)) = sess.opts.pretty {
if let Some(PpMode::Source(PpSourceMode::EveryBodyLoops)) = sess.opts.pretty {
tracing::debug!("replacing bodies with loop {{}}");
util::ReplaceBodyWithLoop::new(&mut resolver).visit_crate(&mut krate);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ rustc_queries! {
desc { |tcx| "computing normalized predicates of `{}`", tcx.def_path_str(def_id) }
}

/// Like `param_env`, but returns the `ParamEnv in `Reveal::All` mode.
/// Like `param_env`, but returns the `ParamEnv` in `Reveal::All` mode.
/// Prefer this over `tcx.param_env(def_id).with_reveal_all_normalized(tcx)`,
/// as this method is more efficient.
query param_env_reveal_all_normalized(def_id: DefId) -> ty::ParamEnv<'tcx> {
Expand Down
117 changes: 64 additions & 53 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2057,40 +2057,21 @@ fn parse_pretty(
debugging_opts: &DebuggingOptions,
efmt: ErrorOutputType,
) -> Option<PpMode> {
let pretty = if debugging_opts.unstable_options {
matches.opt_default("pretty", "normal").map(|a| {
// stable pretty-print variants only
parse_pretty_inner(efmt, &a, false)
})
} else {
None
};

return if pretty.is_none() {
debugging_opts.unpretty.as_ref().map(|a| {
// extended with unstable pretty-print variants
parse_pretty_inner(efmt, &a, true)
})
} else {
pretty
};

fn parse_pretty_inner(efmt: ErrorOutputType, name: &str, extended: bool) -> PpMode {
use PpMode::*;
use PpSourceMode::*;
let first = match (name, extended) {
("normal", _) => PpmSource(PpmNormal),
("identified", _) => PpmSource(PpmIdentified),
("everybody_loops", true) => PpmSource(PpmEveryBodyLoops),
("expanded", _) => PpmSource(PpmExpanded),
("expanded,identified", _) => PpmSource(PpmExpandedIdentified),
("expanded,hygiene", _) => PpmSource(PpmExpandedHygiene),
("hir", true) => PpmHir(PpmNormal),
("hir,identified", true) => PpmHir(PpmIdentified),
("hir,typed", true) => PpmHir(PpmTyped),
("hir-tree", true) => PpmHirTree(PpmNormal),
("mir", true) => PpmMir,
("mir-cfg", true) => PpmMirCFG,
("normal", _) => Source(PpSourceMode::Normal),
("identified", _) => Source(PpSourceMode::Identified),
("everybody_loops", true) => Source(PpSourceMode::EveryBodyLoops),
("expanded", _) => Source(PpSourceMode::Expanded),
("expanded,identified", _) => Source(PpSourceMode::ExpandedIdentified),
("expanded,hygiene", _) => Source(PpSourceMode::ExpandedHygiene),
("hir", true) => Hir(PpHirMode::Normal),
("hir,identified", true) => Hir(PpHirMode::Identified),
("hir,typed", true) => Hir(PpHirMode::Typed),
("hir-tree", true) => HirTree,
("mir", true) => Mir,
("mir-cfg", true) => MirCFG,
_ => {
if extended {
early_error(
Expand Down Expand Up @@ -2119,6 +2100,18 @@ fn parse_pretty(
tracing::debug!("got unpretty option: {:?}", first);
first
}

if debugging_opts.unstable_options {
if let Some(a) = matches.opt_default("pretty", "normal") {
// stable pretty-print variants only
return Some(parse_pretty_inner(efmt, &a, false));
}
}

debugging_opts.unpretty.as_ref().map(|a| {
// extended with unstable pretty-print variants
parse_pretty_inner(efmt, &a, true)
})
}

pub fn make_crate_type_option() -> RustcOptGroup {
Expand Down Expand Up @@ -2226,45 +2219,63 @@ impl fmt::Display for CrateType {

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpSourceMode {
PpmNormal,
PpmEveryBodyLoops,
PpmExpanded,
PpmIdentified,
PpmExpandedIdentified,
PpmExpandedHygiene,
PpmTyped,
/// `--pretty=normal`
Normal,
/// `-Zunpretty=everybody_loops`
EveryBodyLoops,
/// `--pretty=expanded`
Expanded,
/// `--pretty=identified`
Identified,
/// `--pretty=expanded,identified`
ExpandedIdentified,
/// `--pretty=expanded,hygiene`
ExpandedHygiene,
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpHirMode {
/// `-Zunpretty=hir`
Normal,
/// `-Zunpretty=hir,identified`
Identified,
/// `-Zunpretty=hir,typed`
Typed,
}

#[derive(Copy, Clone, PartialEq, Debug)]
pub enum PpMode {
PpmSource(PpSourceMode),
PpmHir(PpSourceMode),
PpmHirTree(PpSourceMode),
PpmMir,
PpmMirCFG,
/// Options that print the source code, i.e.
/// `--pretty` and `-Zunpretty=everybody_loops`
Source(PpSourceMode),
/// Options that print the HIR, i.e. `-Zunpretty=hir`
Hir(PpHirMode),
/// `-Zunpretty=hir-tree`
HirTree,
/// `-Zunpretty=mir`
Mir,
/// `-Zunpretty=mir-cfg`
MirCFG,
}

impl PpMode {
pub fn needs_ast_map(&self) -> bool {
use PpMode::*;
use PpSourceMode::*;
match *self {
PpmSource(PpmNormal | PpmIdentified) => false,
Source(Normal | Identified) => false,

PpmSource(
PpmExpanded | PpmEveryBodyLoops | PpmExpandedIdentified | PpmExpandedHygiene,
)
| PpmHir(_)
| PpmHirTree(_)
| PpmMir
| PpmMirCFG => true,
PpmSource(PpmTyped) => panic!("invalid state"),
Source(Expanded | EveryBodyLoops | ExpandedIdentified | ExpandedHygiene)
| Hir(_)
| HirTree
| Mir
| MirCFG => true,
}
}

pub fn needs_analysis(&self) -> bool {
use PpMode::*;
matches!(*self, PpmMir | PpmMirCFG)
matches!(*self, Mir | MirCFG)
}
}

Expand Down
36 changes: 17 additions & 19 deletions compiler/rustc_typeck/src/check/method/probe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,21 +160,21 @@ pub struct Pick<'tcx> {
pub kind: PickKind<'tcx>,
pub import_ids: SmallVec<[LocalDefId; 1]>,

// Indicates that the source expression should be autoderef'd N times
//
// A = expr | *expr | **expr | ...
/// Indicates that the source expression should be autoderef'd N times
///
/// A = expr | *expr | **expr | ...
pub autoderefs: usize,

// Indicates that an autoref is applied after the optional autoderefs
//
// B = A | &A | &mut A
/// Indicates that an autoref is applied after the optional autoderefs
///
/// B = A | &A | &mut A
pub autoref: Option<hir::Mutability>,

// Indicates that the source expression should be "unsized" to a
// target type. This should probably eventually go away in favor
// of just coercing method receivers.
//
// C = B | unsize(B)
/// Indicates that the source expression should be "unsized" to a
/// target type. This should probably eventually go away in favor
/// of just coercing method receivers.
///
/// C = B | unsize(B)
pub unsize: Option<Ty<'tcx>>,
}

Expand Down Expand Up @@ -1091,19 +1091,17 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
.next()
}

/// For each type `T` in the step list, this attempts to find a method where
/// the (transformed) self type is exactly `T`. We do however do one
/// transformation on the adjustment: if we are passing a region pointer in,
/// we will potentially *reborrow* it to a shorter lifetime. This allows us
/// to transparently pass `&mut` pointers, in particular, without consuming
/// them for their entire lifetime.
fn pick_by_value_method(
&mut self,
step: &CandidateStep<'tcx>,
self_ty: Ty<'tcx>,
) -> Option<PickResult<'tcx>> {
//! For each type `T` in the step list, this attempts to find a
//! method where the (transformed) self type is exactly `T`. We
//! do however do one transformation on the adjustment: if we
//! are passing a region pointer in, we will potentially
//! *reborrow* it to a shorter lifetime. This allows us to
//! transparently pass `&mut` pointers, in particular, without
//! consuming them for their entire lifetime.

if step.unsize {
return None;
}
Expand Down
Loading