diff --git a/pyupgrade.py b/pyupgrade.py
index c7a8d26..2f8626c 100644
--- a/pyupgrade.py
+++ b/pyupgrade.py
@@ -233,6 +233,8 @@ def _victims(tokens, start, arg, gen):
                 ends.extend((i - 1, i))
             else:
                 ends.append(i)
+            if len(brace_stack) > 1 and tokens[i + 1].src == ',':
+                ends.append(i + 1)
 
         if is_end_brace:
             brace_stack.pop()
@@ -245,9 +247,9 @@ def _victims(tokens, start, arg, gen):
         while tokens[i].name in NON_CODING_TOKENS:
             i -= 1
         if tokens[i].src == ',':
-            ends = sorted(set(ends + [i]))
+            ends.append(i)
 
-    return Victims(starts, ends, first_comma_index, arg_index)
+    return Victims(starts, sorted(set(ends)), first_comma_index, arg_index)
 
 
 def _find_token(tokens, i, token):  # type: (List[Token], int, Token) -> int

`set` with trailing comma after list causes syntax error
```python
set(
    [
        1, 2, 3,
    ],
)
```

currently gets rewritten to (`SyntaxError`)

```python
{
        1, 2, 3,
    ,
}
```
diff --git a/tests/set_literals_test.py b/tests/set_literals_test.py
index 22ac4d6..50363be 100644
--- a/tests/set_literals_test.py
+++ b/tests/set_literals_test.py
@@ -85,6 +85,16 @@ def test_fix_sets_noop(s):
             '    x for x in y\n'
             '}',
         ),
+        (
+            'set(\n'
+            '    [\n'
+            '        99, 100,\n'
+            '    ],\n'
+            ')\n',
+            '{\n'
+            '        99, 100,\n'
+            '}\n',
+        ),
     ),
 )
 def test_sets(s, expected):

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest
apt-get update apt-get install -y gcc
3.6
requirements-dev.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
attrs==22.2.0
certifi==2021.5.30
cfgv==3.3.1
coverage==6.2
distlib==0.3.9
filelock==3.4.1
flake8==5.0.4
identify==2.4.4
importlib-metadata==4.2.0
importlib-resources==5.2.3
iniconfig==1.1.1
mccabe==0.7.0
mock==5.2.0
nodeenv==1.6.0
packaging==21.3
platformdirs==2.4.0
pluggy==1.0.0
pre-commit==2.17.0
py==1.11.0
pycodestyle==2.9.1
pyflakes==2.5.0
pyparsing==3.1.4
pytest==7.0.1
-e git+https://github.com/asottile/pyupgrade.git@8faebaaccd3bd25ed0643b2a07e8cd10b17a4f68#egg=pyupgrade
PyYAML==6.0.1
tokenize-rt==4.2.1
toml==0.10.2
tomli==1.2.3
typing_extensions==4.1.1
virtualenv==20.16.2
zipp==3.6.0

name: pyupgrade
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - attrs==22.2.0
      - cfgv==3.3.1
      - coverage==6.2
      - distlib==0.3.9
      - filelock==3.4.1
      - flake8==5.0.4
      - identify==2.4.4
      - importlib-metadata==4.2.0
      - importlib-resources==5.2.3
      - iniconfig==1.1.1
      - mccabe==0.7.0
      - mock==5.2.0
      - nodeenv==1.6.0
      - packaging==21.3
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pre-commit==2.17.0
      - py==1.11.0
      - pycodestyle==2.9.1
      - pyflakes==2.5.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pyyaml==6.0.1
      - tokenize-rt==4.2.1
      - toml==0.10.2
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - virtualenv==20.16.2
      - zipp==3.6.0
prefix: /opt/conda/envs/pyupgrade

tests/set_literals_test.py::test_sets[set(\n
tests/set_literals_test.py::test_fix_sets_noop[set()] tests/set_literals_test.py::test_fix_sets_noop[set((\n))] tests/set_literals_test.py::test_fix_sets_noop[set tests/set_literals_test.py::test_sets[set(())-set()] tests/set_literals_test.py::test_sets[set([])-set()] tests/set_literals_test.py::test_sets[set(( tests/set_literals_test.py::test_sets[set((1, tests/set_literals_test.py::test_sets[set([1, tests/set_literals_test.py::test_sets[set(x tests/set_literals_test.py::test_sets[set([x tests/set_literals_test.py::test_sets[set((x tests/set_literals_test.py::test_sets[set(((1, tests/set_literals_test.py::test_sets[set((a, tests/set_literals_test.py::test_sets[set([(1, tests/set_literals_test.py::test_sets[set([((1, tests/set_literals_test.py::test_sets[set((((1, tests/set_literals_test.py::test_sets[set(\n(1, tests/set_literals_test.py::test_sets[set((\n1,\n2,\n))\n-{\n1,\n2,\n}\n] tests/set_literals_test.py::test_sets[set((frozenset(set((1, tests/set_literals_test.py::test_sets[set((1,))-{1}] tests/set_literals_test.py::test_sets_generators_trailing_commas[set(x tests/set_literals_test.py::test_sets_generators_trailing_commas[set(\n
pyupgrade.py
pyupgrade.py