From c9be1a71b69fb99f9a10b1ba058138d374b5b3a9 Mon Sep 17 00:00:00 2001 From: yukang Date: Sat, 5 Aug 2023 15:58:26 +0800 Subject: [PATCH 1/5] Remove invalid lint when there is a generic argument in prefix path --- compiler/rustc_resolve/src/late.rs | 3 ++- ...-114433-invalid-unused-qualifications-suggestion.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 tests/ui/resolve/issue-114433-invalid-unused-qualifications-suggestion.rs diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 7b590d16d8ce..06da00f1135a 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -3944,11 +3944,12 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> { if path.len() > 1 && let Some(res) = result.full_res() + && let Some((&last_segment, prev_segs)) = path.split_last() + && prev_segs.iter().all(|seg| !seg.has_generic_args) && res != Res::Err && path[0].ident.name != kw::PathRoot && path[0].ident.name != kw::DollarCrate { - let last_segment = *path.last().unwrap(); let unqualified_result = { match self.resolve_path(&[last_segment], Some(ns), None) { PathResult::NonModule(path_res) => path_res.expect_full_res(), diff --git a/tests/ui/resolve/issue-114433-invalid-unused-qualifications-suggestion.rs b/tests/ui/resolve/issue-114433-invalid-unused-qualifications-suggestion.rs new file mode 100644 index 000000000000..83349dd3350b --- /dev/null +++ b/tests/ui/resolve/issue-114433-invalid-unused-qualifications-suggestion.rs @@ -0,0 +1,10 @@ +#![deny(unused_qualifications)] +// check-pass +fn bar() { + match Option::>::None { + Some(v) => {} + None => {} + } +} + +fn main() {} From 9625fc583949e42234f11377cefa2f6115f18c11 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Sat, 5 Aug 2023 12:47:05 +0200 Subject: [PATCH 2/5] Migrate GUI colors test to original CSS color format --- tests/rustdoc-gui/scrape-examples-toggle.goml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/rustdoc-gui/scrape-examples-toggle.goml b/tests/rustdoc-gui/scrape-examples-toggle.goml index 9cec6d2bbe84..f742b3186e5b 100644 --- a/tests/rustdoc-gui/scrape-examples-toggle.goml +++ b/tests/rustdoc-gui/scrape-examples-toggle.goml @@ -28,18 +28,18 @@ define-function: ( call-function: ("check-color", { "theme": "ayu", - "toggle_line_color": "rgb(153, 153, 153)", - "toggle_line_hover_color": "rgb(197, 197, 197)", + "toggle_line_color": "#999", + "toggle_line_hover_color": "#c5c5c5", }) call-function: ("check-color", { "theme": "dark", - "toggle_line_color": "rgb(153, 153, 153)", - "toggle_line_hover_color": "rgb(197, 197, 197)", + "toggle_line_color": "#999", + "toggle_line_hover_color": "#c5c5c5", }) call-function: ("check-color", { "theme": "light", - "toggle_line_color": "rgb(204, 204, 204)", - "toggle_line_hover_color": "rgb(153, 153, 153)", + "toggle_line_color": "#ccc", + "toggle_line_hover_color": "#999", }) // Toggling all docs will close additional examples From 55bf8108217e300e977b81504316c564f4a5c3d5 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 5 Aug 2023 20:09:31 +0000 Subject: [PATCH 3/5] Also report when goals go from ok to error --- compiler/rustc_trait_selection/src/solve/eval_ctxt.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs index 5ec9ddfe64ae..60c49f665a6a 100644 --- a/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs +++ b/compiler/rustc_trait_selection/src/solve/eval_ctxt.rs @@ -391,13 +391,19 @@ impl<'a, 'tcx> EvalCtxt<'a, 'tcx> { debug!("rerunning goal to check result is stable"); self.search_graph.reset_encountered_overflow(encountered_overflow); let (_orig_values, canonical_goal) = self.canonicalize_goal(goal); - let new_canonical_response = EvalCtxt::evaluate_canonical_goal( + let Ok(new_canonical_response) = EvalCtxt::evaluate_canonical_goal( self.tcx(), self.search_graph, canonical_goal, // FIXME(-Ztrait-solver=next): we do not track what happens in `evaluate_canonical_goal` &mut ProofTreeBuilder::new_noop(), - )?; + ) else { + bug!( + "goal went from {certainty:?} to error: re-canonicalized goal={canonical_goal:#?} \ + first_response={canonical_response:#?}, + second response was error" + ); + }; // We only check for modulo regions as we convert all regions in // the input to new existentials, even if they're expected to be // `'static` or a placeholder region. From b71f2becb293ccab09d75220bb168871cae88ee5 Mon Sep 17 00:00:00 2001 From: Urgau Date: Fri, 4 Aug 2023 23:40:55 +0200 Subject: [PATCH 4/5] Avoid invalid NaN lint machine-applicable suggestion in const context --- compiler/rustc_lint/src/lints.rs | 2 +- compiler/rustc_lint/src/types.rs | 13 ++++++++----- tests/ui/lint/invalid-nan-comparison.stderr | 5 ----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_lint/src/lints.rs b/compiler/rustc_lint/src/lints.rs index 968172693a93..6cae52248f16 100644 --- a/compiler/rustc_lint/src/lints.rs +++ b/compiler/rustc_lint/src/lints.rs @@ -1467,7 +1467,7 @@ pub enum InvalidNanComparisons { #[diag(lint_invalid_nan_comparisons_eq_ne)] EqNe { #[subdiagnostic] - suggestion: InvalidNanComparisonsSuggestion, + suggestion: Option, }, #[diag(lint_invalid_nan_comparisons_lt_le_gt_ge)] LtLeGtGe, diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 226d01b79a89..7ee515b4b72e 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -572,32 +572,35 @@ fn lint_nan<'tcx>( } fn eq_ne( + cx: &LateContext<'_>, e: &hir::Expr<'_>, l: &hir::Expr<'_>, r: &hir::Expr<'_>, f: impl FnOnce(Span, Span) -> InvalidNanComparisonsSuggestion, ) -> InvalidNanComparisons { - let suggestion = + let suggestion = (!cx.tcx.hir().is_inside_const_context(e.hir_id)).then(|| { if let Some(l_span) = l.span.find_ancestor_inside(e.span) && - let Some(r_span) = r.span.find_ancestor_inside(e.span) { + let Some(r_span) = r.span.find_ancestor_inside(e.span) + { f(l_span, r_span) } else { InvalidNanComparisonsSuggestion::Spanless - }; + } + }); InvalidNanComparisons::EqNe { suggestion } } let lint = match binop.node { hir::BinOpKind::Eq | hir::BinOpKind::Ne if is_nan(cx, l) => { - eq_ne(e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful { + eq_ne(cx, e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful { nan_plus_binop: l_span.until(r_span), float: r_span.shrink_to_hi(), neg: (binop.node == hir::BinOpKind::Ne).then(|| r_span.shrink_to_lo()), }) } hir::BinOpKind::Eq | hir::BinOpKind::Ne if is_nan(cx, r) => { - eq_ne(e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful { + eq_ne(cx, e, l, r, |l_span, r_span| InvalidNanComparisonsSuggestion::Spanful { nan_plus_binop: l_span.shrink_to_hi().to(r_span), float: l_span.shrink_to_hi(), neg: (binop.node == hir::BinOpKind::Ne).then(|| l_span.shrink_to_lo()), diff --git a/tests/ui/lint/invalid-nan-comparison.stderr b/tests/ui/lint/invalid-nan-comparison.stderr index 054c06d38b30..f2d55c107ba0 100644 --- a/tests/ui/lint/invalid-nan-comparison.stderr +++ b/tests/ui/lint/invalid-nan-comparison.stderr @@ -5,11 +5,6 @@ LL | const TEST: bool = 5f32 == f32::NAN; | ^^^^^^^^^^^^^^^^ | = note: `#[warn(invalid_nan_comparisons)]` on by default -help: use `f32::is_nan()` or `f64::is_nan()` instead - | -LL - const TEST: bool = 5f32 == f32::NAN; -LL + const TEST: bool = 5f32.is_nan(); - | warning: incorrect NaN comparison, NaN cannot be directly compared to itself --> $DIR/invalid-nan-comparison.rs:14:5 From 3b3e466e36a74295bb66450d1858e3d7868d8a5d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sat, 5 Aug 2023 17:04:30 -0700 Subject: [PATCH 5/5] Add FIXME as reminder to restore suggestion later --- compiler/rustc_lint/src/types.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 7ee515b4b72e..3dd66d3637c9 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -578,6 +578,7 @@ fn lint_nan<'tcx>( r: &hir::Expr<'_>, f: impl FnOnce(Span, Span) -> InvalidNanComparisonsSuggestion, ) -> InvalidNanComparisons { + // FIXME(#72505): This suggestion can be restored if `f{32,64}::is_nan` is made const. let suggestion = (!cx.tcx.hir().is_inside_const_context(e.hir_id)).then(|| { if let Some(l_span) = l.span.find_ancestor_inside(e.span) && let Some(r_span) = r.span.find_ancestor_inside(e.span)