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 7 pull requests #133877

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
9d1f790
Add warn-by-default lint against unpredictable fn pointer comparisons
Urgau Nov 9, 2023
5e34c2e
Drop uplifted `clippy::fn_address_comparisons`
Urgau Dec 10, 2023
8ce6357
Allow fn pointers comparisons lint in UI tests
Urgau Dec 10, 2023
7b06fcf
Allow fn pointers comparisons lint in library
Urgau Dec 12, 2023
f613636
Rename `core_pattern_type` and `core_pattern_types` lib feature gate…
oli-obk Dec 4, 2024
1b449e1
Do not emit empty suggestion
estebank Dec 4, 2024
05c34cc
Fix suggestion when shorthand self has erroneous type
compiler-errors Mar 8, 2024
c620505
On `const` pattern errors, point at the `const` item definition
estebank Nov 20, 2024
cc492ed
Tweak unevaluated constant in pattern error
estebank Nov 20, 2024
c0f0008
Tweak ptr in pattern error
estebank Nov 20, 2024
87ddc1e
Point at generic param through which a const is used in a pattern
estebank Nov 20, 2024
253eb95
Tweak output of some const pattern errors
estebank Nov 20, 2024
a6040bc
Specify type kind of constant that can't be used in patterns
estebank Nov 20, 2024
fb2f6a4
Reword message for non-structural type constant in pattern
estebank Nov 20, 2024
335d05a
Add additional context for non-sructural type constant used in pattern
estebank Nov 20, 2024
27a1880
Add context to fall-through "const pattern of non-structural type" error
estebank Nov 20, 2024
d136b31
Add more context to fall-through "const pattern of non-structural typ…
estebank Nov 20, 2024
da58406
fix test
estebank Nov 20, 2024
81291ec
No need to create placeholders for GAT args in confirm_object_candidate
compiler-errors Dec 4, 2024
4e6a401
review comments: reword messages and simplify logic
estebank Dec 4, 2024
03aec5d
fn_sig_for_fn_abi should return a ty::FnSig, no need for a binder
compiler-errors Nov 16, 2024
6ee20ac
Rollup merge of #118833 - Urgau:lint_function_pointer_comparisons, r=…
fmease Dec 4, 2024
81bbc9c
Rollup merge of #122161 - compiler-errors:shorthand-self, r=fmease
fmease Dec 4, 2024
7660ac7
Rollup merge of #133233 - estebank:const-errors, r=Nadrieril
fmease Dec 4, 2024
3e8e092
Rollup merge of #133843 - estebank:empty-semi-sugg, r=jieyouxu
fmease Dec 4, 2024
c4e6438
Rollup merge of #133863 - oli-obk:push-pystoxvtvssx, r=lqd
fmease Dec 4, 2024
9ec5f40
Rollup merge of #133872 - compiler-errors:simplify-gat-check, r=oli-obk
fmease Dec 4, 2024
ccb6845
Rollup merge of #133874 - compiler-errors:fn-sig-binder, r=oli-obk
fmease Dec 4, 2024
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
Prev Previous commit
Next Next commit
Tweak output of some const pattern errors
- Add primary span labels.
- Point at const generic parameter used as pattern.
- Point at statics used as pattern.
- Point at let bindings used in const pattern.
  • Loading branch information
estebank committed Dec 4, 2024
commit 253eb95d4582e1abffc4a74dd8eaccd5b94b5d6f
10 changes: 9 additions & 1 deletion compiler/rustc_mir_build/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ mir_build_confused = missing patterns are not covered because `{$variable}` is i

mir_build_const_defined_here = constant defined here

mir_build_const_param_in_pattern = const parameters cannot be referenced in patterns
mir_build_const_param_in_pattern = constant parameters cannot be referenced in patterns
.label = can't be used in patterns
mir_build_const_param_in_pattern_def = constant defined here

mir_build_const_pattern_depends_on_generic_parameter = constant pattern depends on a generic parameter, which is not allowed
.label = `const` depends on a generic parameter
Expand Down Expand Up @@ -247,10 +249,12 @@ mir_build_mutation_of_layout_constrained_field_requires_unsafe_unsafe_op_in_unsa
.label = mutation of layout constrained field

mir_build_nan_pattern = cannot use NaN in patterns
.label = evaluates to `NaN`, which is not allowed in patterns
.note = NaNs compare inequal to everything, even themselves, so this pattern would never match
.help = try using the `is_nan` method instead

mir_build_non_const_path = runtime values cannot be referenced in patterns
.label = references a runtime value

mir_build_non_empty_never_pattern =
mismatched types
Expand All @@ -270,6 +274,7 @@ mir_build_non_exhaustive_patterns_type_not_empty = non-exhaustive patterns: type

mir_build_non_partial_eq_match =
to use a constant of type `{$non_peq_ty}` in a pattern, the type must implement `PartialEq`
.label = constant of non-structural type

mir_build_pattern_not_covered = refutable pattern in {$origin}
.pattern_ty = the matched value is of type `{$pattern_ty}`
Expand All @@ -288,6 +293,8 @@ mir_build_rustc_box_attribute_error = `#[rustc_box]` attribute used incorrectly
.missing_box = `#[rustc_box]` requires the `owned_box` lang item

mir_build_static_in_pattern = statics cannot be referenced in patterns
.label = can't be used in patterns
mir_build_static_in_pattern_def = `static` defined here

mir_build_suggest_attempted_int_lit = alternatively, you could prepend the pattern with an underscore to define a new named variable; identifiers cannot begin with digits

Expand Down Expand Up @@ -339,6 +346,7 @@ mir_build_union_field_requires_unsafe_unsafe_op_in_unsafe_fn_allowed =
.label = access to union field

mir_build_union_pattern = cannot use unions in constant patterns
.label = can't use a `union` here

mir_build_unreachable_making_this_unreachable = collectively making this unreachable

Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_mir_build/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -631,20 +631,27 @@ pub(crate) struct NonExhaustiveMatchAllArmsGuarded;
#[diag(mir_build_static_in_pattern, code = E0158)]
pub(crate) struct StaticInPattern {
#[primary_span]
#[label]
pub(crate) span: Span,
#[label(mir_build_static_in_pattern_def)]
pub(crate) static_span: Span,
}

#[derive(Diagnostic)]
#[diag(mir_build_const_param_in_pattern, code = E0158)]
pub(crate) struct ConstParamInPattern {
#[primary_span]
#[label]
pub(crate) span: Span,
#[label(mir_build_const_param_in_pattern_def)]
pub(crate) const_span: Span,
}

#[derive(Diagnostic)]
#[diag(mir_build_non_const_path, code = E0080)]
pub(crate) struct NonConstPath {
#[primary_span]
#[label]
pub(crate) span: Span,
}

Expand Down Expand Up @@ -869,6 +876,7 @@ pub(crate) enum Conflict {
#[diag(mir_build_union_pattern)]
pub(crate) struct UnionPattern {
#[primary_span]
#[label]
pub(crate) span: Span,
}

Expand All @@ -886,6 +894,7 @@ pub(crate) struct TypeNotStructural<'tcx> {
#[diag(mir_build_non_partial_eq_match)]
pub(crate) struct TypeNotPartialEq<'tcx> {
#[primary_span]
#[label]
pub(crate) span: Span,
pub(crate) non_peq_ty: Ty<'tcx>,
}
Expand All @@ -912,6 +921,7 @@ pub(crate) struct UnsizedPattern<'tcx> {
#[help]
pub(crate) struct NaNPattern {
#[primary_span]
#[label]
pub(crate) span: Span,
}

Expand Down
14 changes: 10 additions & 4 deletions compiler/rustc_mir_build/src/thir/pattern/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,17 @@ impl<'a, 'tcx> PatCtxt<'a, 'tcx> {
| Res::SelfCtor(..) => PatKind::Leaf { subpatterns },
_ => {
let e = match res {
Res::Def(DefKind::ConstParam, _) => {
self.tcx.dcx().emit_err(ConstParamInPattern { span })
Res::Def(DefKind::ConstParam, def_id) => {
self.tcx.dcx().emit_err(ConstParamInPattern {
span,
const_span: self.tcx().def_span(def_id),
})
}
Res::Def(DefKind::Static { .. }, _) => {
self.tcx.dcx().emit_err(StaticInPattern { span })
Res::Def(DefKind::Static { .. }, def_id) => {
self.tcx.dcx().emit_err(StaticInPattern {
span,
static_span: self.tcx().def_span(def_id),
})
}
_ => self.tcx.dcx().emit_err(NonConstPath { span }),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/binding/const-param.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

fn check<const N: usize>() {
match 1 {
N => {} //~ ERROR const parameters cannot be referenced in patterns
N => {} //~ ERROR constant parameters cannot be referenced in patterns
_ => {}
}
}
Expand Down
7 changes: 5 additions & 2 deletions tests/ui/binding/const-param.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
error[E0158]: const parameters cannot be referenced in patterns
error[E0158]: constant parameters cannot be referenced in patterns
--> $DIR/const-param.rs:5:9
|
LL | fn check<const N: usize>() {
| -------------- constant defined here
LL | match 1 {
LL | N => {}
| ^
| ^ can't be used in patterns

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const_in_pattern/issue-65466.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const C: &[O<B>] = &[O::None];
| ---------------- constant defined here
...
LL | C => (),
| ^
| ^ constant of non-structural type

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const NO_PARTIAL_EQ_NONE: Option<NoPartialEq> = None;
| --------------------------------------------- constant defined here
...
LL | NO_PARTIAL_EQ_NONE => println!("NO_PARTIAL_EQ_NONE"),
| ^^^^^^^^^^^^^^^^^^
| ^^^^^^^^^^^^^^^^^^ constant of non-structural type

error: aborting due to 1 previous error

2 changes: 1 addition & 1 deletion tests/ui/match/issue-72896-non-partial-eq-const.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const CONST_SET: EnumSet<Enum8> = EnumSet { __enumset_underlying: 3 };
| ------------------------------- constant defined here
...
LL | CONST_SET => { /* ok */ }
| ^^^^^^^^^
| ^^^^^^^^^ constant of non-structural type

error: aborting due to 1 previous error

14 changes: 10 additions & 4 deletions tests/ui/pattern/non-constant-in-const-path.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,31 @@ error[E0080]: runtime values cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:8:15
|
LL | let 0u8..=x = 0;
| ^
| ^ references a runtime value

error[E0158]: statics cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:10:15
|
LL | static FOO: u8 = 10;
| -------------- `static` defined here
...
LL | let 0u8..=FOO = 0;
| ^^^
| ^^^ can't be used in patterns

error[E0080]: runtime values cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:13:15
|
LL | 0 ..= x => {}
| ^
| ^ references a runtime value

error[E0158]: statics cannot be referenced in patterns
--> $DIR/non-constant-in-const-path.rs:15:15
|
LL | static FOO: u8 = 10;
| -------------- `static` defined here
...
LL | 0 ..= FOO => {}
| ^^^
| ^^^ can't be used in patterns

error: aborting due to 4 previous errors

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const A: &[B] = &[];
| ------------- constant defined here
...
LL | A => (),
| ^
| ^ constant of non-structural type

error: aborting due to 1 previous error

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | NAN => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -17,7 +17,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | [NAN, _] => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -29,7 +29,7 @@ LL | const C: MyType<f32> = MyType(f32::NAN);
| -------------------- constant defined here
...
LL | C => {},
| ^
| ^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -41,7 +41,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | NAN..=1.0 => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -53,7 +53,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | -1.0..=NAN => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -65,7 +65,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | NAN.. => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand All @@ -77,7 +77,7 @@ LL | const NAN: f64 = f64::NAN;
| -------------- constant defined here
...
LL | ..NAN => {},
| ^^^
| ^^^ evaluates to `NaN`, which is not allowed in patterns
|
= note: NaNs compare inequal to everything, even themselves, so this pattern would never match
= help: try using the `is_nan` method instead
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/union/union-const-pat.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | const C: U = U { a: 10 };
| ---------- constant defined here
...
LL | C => {}
| ^
| ^ can't use a `union` here

error: aborting due to 1 previous error