-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Avoid a bunch of booleans in favor of Result<(), ErrorGuaranteed> as that more robustly proves that an error has been emitted #126317
Changes from 3 commits
185a48d
3da9289
be464b8
4d72c42
9065889
6299071
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,16 +113,16 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
&self, | ||
sp: Span, | ||
expr: &'tcx hir::Expr<'tcx>, | ||
method: Result<MethodCallee<'tcx>, ()>, | ||
method: Result<MethodCallee<'tcx>, ErrorGuaranteed>, | ||
args_no_rcvr: &'tcx [hir::Expr<'tcx>], | ||
tuple_arguments: TupleArgumentsFlag, | ||
expected: Expectation<'tcx>, | ||
) -> Ty<'tcx> { | ||
let has_error = match method { | ||
Ok(method) => method.args.references_error() || method.sig.references_error(), | ||
Err(_) => true, | ||
Ok(method) => method.args.error_reported().and(method.sig.error_reported()), | ||
Err(guar) => Err(guar), | ||
}; | ||
if has_error { | ||
if let Err(guar) = has_error { | ||
let err_inputs = self.err_args(args_no_rcvr.len()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. make |
||
|
||
let err_inputs = match tuple_arguments { | ||
|
@@ -140,7 +140,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |
tuple_arguments, | ||
method.ok().map(|method| method.def_id), | ||
); | ||
return Ty::new_misc_error(self.tcx); | ||
return Ty::new_error(self.tcx, guar); | ||
} | ||
|
||
let method = method.unwrap(); | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -33,7 +33,7 @@ use rustc_middle::ty::IsSuggestable; | |||||
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeVisitableExt}; | ||||||
use rustc_span::def_id::DefIdSet; | ||||||
use rustc_span::symbol::{kw, sym, Ident}; | ||||||
use rustc_span::{edit_distance, ExpnKind, FileName, MacroKind, Span}; | ||||||
use rustc_span::{edit_distance, ErrorGuaranteed, ExpnKind, FileName, MacroKind, Span}; | ||||||
use rustc_span::{Symbol, DUMMY_SP}; | ||||||
use rustc_trait_selection::infer::InferCtxtExt; | ||||||
use rustc_trait_selection::traits::error_reporting::on_unimplemented::OnUnimplementedNote; | ||||||
|
@@ -192,7 +192,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
error: MethodError<'tcx>, | ||||||
expected: Expectation<'tcx>, | ||||||
trait_missing_method: bool, | ||||||
) -> Option<Diag<'_>> { | ||||||
) -> Result<Diag<'_>, ErrorGuaranteed> { | ||||||
let (span, sugg_span, source, item_name, args) = match self.tcx.hir_node(call_id) { | ||||||
hir::Node::Expr(&hir::Expr { | ||||||
kind: hir::ExprKind::MethodCall(segment, rcvr, args, _), | ||||||
|
@@ -226,9 +226,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
}; | ||||||
|
||||||
// Avoid suggestions when we don't know what's going on. | ||||||
if rcvr_ty.references_error() { | ||||||
return None; | ||||||
} | ||||||
rcvr_ty.error_reported()?; | ||||||
|
||||||
match error { | ||||||
MethodError::NoMatch(mut no_match_data) => { | ||||||
|
@@ -265,7 +263,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
&mut sources, | ||||||
Some(sugg_span), | ||||||
); | ||||||
err.emit(); | ||||||
return Err(err.emit()); | ||||||
} | ||||||
|
||||||
MethodError::PrivateMatch(kind, def_id, out_of_scope_traits) => { | ||||||
|
@@ -286,7 +284,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
.unwrap_or_else(|| self.tcx.def_span(def_id)); | ||||||
err.span_label(sp, format!("private {kind} defined here")); | ||||||
self.suggest_valid_traits(&mut err, item_name, out_of_scope_traits, true); | ||||||
err.emit(); | ||||||
return Err(err.emit()); | ||||||
} | ||||||
|
||||||
MethodError::IllegalSizedBound { candidates, needs_mut, bound_span, self_expr } => { | ||||||
|
@@ -343,12 +341,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
} | ||||||
} | ||||||
} | ||||||
err.emit(); | ||||||
return Err(err.emit()); | ||||||
} | ||||||
|
||||||
MethodError::BadReturnType => bug!("no return type expectations but got BadReturnType"), | ||||||
} | ||||||
None | ||||||
} | ||||||
|
||||||
fn suggest_missing_writer(&self, rcvr_ty: Ty<'tcx>, rcvr_expr: &hir::Expr<'tcx>) -> Diag<'_> { | ||||||
|
@@ -576,7 +573,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
no_match_data: &mut NoMatchData<'tcx>, | ||||||
expected: Expectation<'tcx>, | ||||||
trait_missing_method: bool, | ||||||
) -> Option<Diag<'_>> { | ||||||
) -> Result<Diag<'_>, ErrorGuaranteed> { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
let mode = no_match_data.mode; | ||||||
let tcx = self.tcx; | ||||||
let rcvr_ty = self.resolve_vars_if_possible(rcvr_ty); | ||||||
|
@@ -608,24 +605,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
|
||||||
// We could pass the file for long types into these two, but it isn't strictly necessary | ||||||
// given how targeted they are. | ||||||
if self.suggest_wrapping_range_with_parens( | ||||||
self.suggest_wrapping_range_with_parens( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These probably shouldn't be named |
||||||
tcx, | ||||||
rcvr_ty, | ||||||
source, | ||||||
span, | ||||||
item_name, | ||||||
&short_ty_str, | ||||||
) || self.suggest_constraining_numerical_ty( | ||||||
)?; | ||||||
self.suggest_constraining_numerical_ty( | ||||||
tcx, | ||||||
rcvr_ty, | ||||||
source, | ||||||
span, | ||||||
item_kind, | ||||||
item_name, | ||||||
&short_ty_str, | ||||||
) { | ||||||
return None; | ||||||
} | ||||||
)?; | ||||||
span = item_name.span; | ||||||
|
||||||
// Don't show generic arguments when the method can't be found in any implementation (#81576). | ||||||
|
@@ -881,7 +877,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
vec![(span.shrink_to_lo(), format!("into_iter()."))], | ||||||
Applicability::MaybeIncorrect, | ||||||
); | ||||||
return Some(err); | ||||||
return Ok(err); | ||||||
} else if !unsatisfied_predicates.is_empty() && matches!(rcvr_ty.kind(), ty::Param(_)) { | ||||||
// We special case the situation where we are looking for `_` in | ||||||
// `<TypeParam as _>::method` because otherwise the machinery will look for blanket | ||||||
|
@@ -1606,7 +1602,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
} | ||||||
|
||||||
self.note_derefed_ty_has_method(&mut err, source, rcvr_ty, item_name, expected); | ||||||
Some(err) | ||||||
Ok(err) | ||||||
} | ||||||
|
||||||
/// If an appropriate error source is not found, check method chain for possible candidates | ||||||
|
@@ -2259,7 +2255,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
span: Span, | ||||||
item_name: Ident, | ||||||
ty_str: &str, | ||||||
) -> bool { | ||||||
) -> Result<(), ErrorGuaranteed> { | ||||||
if let SelfSource::MethodCall(expr) = source { | ||||||
for (_, parent) in tcx.hir().parent_iter(expr.hir_id).take(5) { | ||||||
if let Node::Expr(parent_expr) = parent { | ||||||
|
@@ -2316,7 +2312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
); | ||||||
if pick.is_ok() { | ||||||
let range_span = parent_expr.span.with_hi(expr.span.hi()); | ||||||
tcx.dcx().emit_err(errors::MissingParenthesesInRange { | ||||||
return Err(tcx.dcx().emit_err(errors::MissingParenthesesInRange { | ||||||
span, | ||||||
ty_str: ty_str.to_string(), | ||||||
method_name: item_name.as_str().to_string(), | ||||||
|
@@ -2325,13 +2321,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
left: range_span.shrink_to_lo(), | ||||||
right: range_span.shrink_to_hi(), | ||||||
}), | ||||||
}); | ||||||
return true; | ||||||
})); | ||||||
} | ||||||
} | ||||||
} | ||||||
} | ||||||
false | ||||||
Ok(()) | ||||||
} | ||||||
|
||||||
fn suggest_constraining_numerical_ty( | ||||||
|
@@ -2343,7 +2338,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
item_kind: &str, | ||||||
item_name: Ident, | ||||||
ty_str: &str, | ||||||
) -> bool { | ||||||
) -> Result<(), ErrorGuaranteed> { | ||||||
let found_candidate = all_traits(self.tcx) | ||||||
.into_iter() | ||||||
.any(|info| self.associated_value(info.def_id, item_name).is_some()); | ||||||
|
@@ -2447,10 +2442,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { | |||||
} | ||||||
_ => {} | ||||||
} | ||||||
err.emit(); | ||||||
return true; | ||||||
return Err(err.emit()); | ||||||
} | ||||||
false | ||||||
Ok(()) | ||||||
} | ||||||
|
||||||
/// For code `rect::area(...)`, | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ pub struct LoggerConfig { | |
pub verbose_thread_ids: Result<String, VarError>, | ||
pub backtrace: Result<String, VarError>, | ||
pub wraptree: Result<String, VarError>, | ||
pub lines: Result<String, VarError>, | ||
} | ||
|
||
impl LoggerConfig { | ||
|
@@ -69,6 +70,7 @@ impl LoggerConfig { | |
verbose_thread_ids: env::var(format!("{env}_THREAD_IDS")), | ||
backtrace: env::var(format!("{env}_BACKTRACE")), | ||
wraptree: env::var(format!("{env}_WRAPTREE")), | ||
lines: env::var(format!("{env}_LINES")), | ||
} | ||
} | ||
} | ||
|
@@ -101,13 +103,19 @@ pub fn init_logger(cfg: LoggerConfig) -> Result<(), Error> { | |
Err(_) => false, | ||
}; | ||
|
||
let lines = match cfg.lines { | ||
Ok(v) => &v == "1", | ||
Err(_) => false, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think a surprising side-effect of this change was to turn off the lines by default? Even when they are turned on, they look very different... much harder than before to just "move up" and find earlier things on the same level of nesting, since the line is now just a snake that moves left and right with the indentation, it no longer properly shows what nesting level we are getting back to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lines were already turned off in an earlier PR by someone else because they broke code folding which allowed you to fold entire sub-spans. After I switched tracing-tree to use the snaky line, you get both the lines (which I find useful) and the code folding, so I made it opt-in. Locally I was replacing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's "code folding"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When you hover over the line numbers in vscode, folding thingies like for directories show up. These are indentation based I think, but in code they may be squirly bracket based |
||
}; | ||
|
||
let mut layer = tracing_tree::HierarchicalLayer::default() | ||
.with_writer(io::stderr) | ||
.with_ansi(color_logs) | ||
.with_targets(true) | ||
.with_verbose_exit(verbose_entry_exit) | ||
.with_verbose_entry(verbose_entry_exit) | ||
.with_indent_amount(2) | ||
.with_indent_lines(lines) | ||
.with_thread_ids(verbose_thread_ids) | ||
.with_thread_names(verbose_thread_ids); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please make
report_method_error
return anErrorGuaranteed
. there's no reason to returnResult<Diag, ErrorGuaranteed>
when the only two callsites just calldiag.emit()
.