WASHINGTON — Legal experts said Wednesday that Housing Secretary Ben Carson likely did not violate federal law when he appeared with President Donald Trump at a campaign rally.

After the appearance Tuesday night, questions were raised on Twitter about whether Carson had violated the federal law known as the Hatch Act, which bars most executive branch officials from using their government positions to influence elections.

Kathleen Clark, an attorney and law professor at Washington University School of Law in St. Louis, says Carson isn’t prohibited from speaking at a campaign event, but Hatch would bar him from invoking or using his official position to engage in partisan political activity.

Housing and Urban Development spokesman Jerry Brown said the agency doesn’t think Carson did anything wrong.

“His travel and lodging were not paid for by the department. He was there in his personal capacity. He didn’t discuss HUD during the speech.”

Brown says the Trump campaign paid expenses for Carson’s trip to Phoenix, where he stood alongside a president still reeling from the widespread condemnation of his response to violence at a Charlottesville, Virginia, protest earlier this month.

Carson spoke to the crowd before Trump. The only black Cabinet member, he talked about his experiences growing up with racism and said that, every time the U.S. has encountered bigotry and division, the country has left those ideologies in “the rear view window.”

An announcer had introduced Carson as the secretary of the Department of Housing and Urban Development. The agency says Carson was re-reading his speech and did not hear the announcer introduce him and reference his title.

Virginia Canter,an ethics counsel at Citizens for Responsibility and Ethics in Washington, says that wasn’t an appropriate use of Carson’s title at a campaign-themed event, but it probably didn’t violate federal law.

“To violate the Hatch Act, a person has to be engaged in political activity while acting in their official capacity,” said Canter. Carson “would have had to been participating in an event that made statements that expressly advocated for or against Trump’s re-election in 2020. None of his comments did that,” she said.

In June, the Office of Special Counsel, an independent agency that investigates federal personnel, reprimanded White House social media director Dan Scavino for violating the Hatch Act. Scavino had tweeted a call to defeat a Republican representative who was often critical of Trump.