Skip to content

Conflict about Some(1|2) in 1.53 #86408

Description

@kkonghao

hi when i use rust 1.53 version some code about pattern match below make me confused,and i think this is a bug or a problem that cannot be ignored.

	let x = Some(2);
	assert!(matches!(x,Some(1 | 2)));//ok x is Some(2)
	assert!(matches!(Some(1),Some(1|2)));//ok
	assert!(matches!(Some(2),Some(1|2)));//ok

	let y = Some(1 | 2);//y is Some(3)
	// assert!(matches!(Some(3),Some(1|2)));// error, Some(1|2) =>is Some(1) | Some(2) or Some(3)?

Activity

  1. bugadani commented on Jun 17, 2021

    @bugadani
    Contributor

    This isn't new at all: rust-lang/rfcs#2535 (comment)

    Since 1|2 already had the same ambiguoity, this has been kind of "ignored" as far as I understand, but don't quote me on the reasoning.

  2. jonas-schievink commented on Jun 17, 2021

    @jonas-schievink
    Contributor

    or-patterns do not function as binary operators. This is working as intended, so closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions